| Task: | Coins |
| Sender: | HIIT AND RUN |
| Submission time: | 2018-05-26 15:37:38 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.67 s | details |
| #2 | ACCEPTED | 0.45 s | details |
| #3 | ACCEPTED | 0.43 s | details |
| #4 | ACCEPTED | 0.44 s | details |
| #5 | WRONG ANSWER | 0.61 s | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:62:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (isojaMatchaavia >= from->size()) ans.push_back(to == &r ? "<" : ">");
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
set<ll> l;
set<ll> r;
vector<ll> backtrackActions;
for (int i=0; i< n; i++) {
ll coin;
cin >> coin;
ll leftOrRight;
cin >> leftOrRight;
backtrackActions.push_back(coin);
backtrackActions.push_back(leftOrRight);
if (leftOrRight == 1) l.insert(coin);
else r.insert(coin);
}
auto to = &r;
auto from = &l;
if (!l.empty()) {
if (r.empty() || *l.rbegin() > *r.rbegin()) {
to = &l;
from = &r;
}
}
ll largest = *to->rbegin();
vector<string> ans;
set<ll> pq;
ll countRemovedSmalls = 0;
ll i = backtrackActions.size() -1;
while (true) {
ll smallestInFrom = (from->empty() ? 0 : *from->begin());
//cout << "largest" << largest << "smallest" << smallestInFrom << endl;
//cout << "from" << from->size() << endl;
ll countSmallerThanFromSmallest = max((ll) 0, smallestInFrom - 1 - countRemovedSmalls);
ll isojaMatchaavia = to->size() - countSmallerThanFromSmallest;
//cout << "isoja" << isojaMatchaavia << endl;
if (isojaMatchaavia >= from->size()) ans.push_back(to == &r ? "<" : ">");
else ans.push_back("?");
if (i <= 2) break;
ll leftOrRight = backtrackActions[i--];
ll coin = backtrackActions[i--];
if (coin < smallestInFrom) {
to->erase(coin);
countRemovedSmalls++;
} else if (coin == smallestInFrom) {
from->erase(coin);
countRemovedSmalls++;
ll newSmallest = (from->empty() ? 0 : *from->begin());
while (!pq.empty() && *pq.begin() < newSmallest) {
pq.erase(pq.begin());
countRemovedSmalls++;
}
} else if (coin == largest) {
to->erase(coin);
largest = (to->empty() ? -1 : *to->rbegin());
//System.out.println("largest " + largest);
if (largest == -1 || (!from->empty() && *from->rbegin() > largest)) {
// swap to and from
auto helper = to;
to = from;
from = helper;
largest = *to->rbegin();
}
pq.insert(coin);
} else {
if (leftOrRight == 2) r.erase(coin);
else l.erase(coin);
pq.insert(coin);
}
}
for (int i=ans.size()-1; i >= 0; i--) {
cout << ans[i] << endl;
}
}
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 200000 175878 1 146174 1 4939 2 181388 1 ... |
| correct output |
|---|
| > > > > > ... |
| user output |
|---|
| > > > > > ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 200000 1 2 2 1 3 2 4 1 ... |
| correct output |
|---|
| < > < > < ... |
| user output |
|---|
| < > < > < ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 200000 1 1 2 1 3 1 4 1 ... |
| correct output |
|---|
| > > > > > ... |
| user output |
|---|
| > > > > > ... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 200000 1 1 2 1 3 1 4 1 ... |
| correct output |
|---|
| > > > > > ... |
| user output |
|---|
| > > > > > ... |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 200000 188909 2 58944 1 26824 1 143263 2 ... |
| correct output |
|---|
| < < ? < < ... |
| user output |
|---|
| < < ? < < ... |
