Submission #976903

# Submission time Handle Problem Language Result Execution time Memory
976903 2024-05-07T08:43:48 Z efedmrlr Zagrade (COI20_zagrade) C++17
100 / 100
549 ms 1636 KB
#include <bits/stdc++.h>

#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)

using namespace std;

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N = 1e5 + 5;
const int INF = 1e9 + 500;
vector<char> res(N);
int n, q;
bool query(int l, int r) {
    cout << "? " << l << " " << r << endl;
    bool x;
    cin >> x;
    return x;
}
void answer() {
    cout << "! ";
    for(int i = 1; i <= n; i++) {
        cout << res[i];
    }
    cout << endl;
}

void solve() {
    cin >> n >> q;
    int l = 1;
    int ops = n / 2;
    deque<int> op;
    op.pb(1);
    for(int r = 2; r <= n; ) {
        bool x = query(l, r);
        if(x) {
            res[r] = ')';
            res[op.back()] = '(';
            ops--;
            op.pop_back();
        }
        else {
            op.pb(r);
        }
        r++;
        if(op.size() > ops) {
            res[op.front()] = ')';
            op.pop_front();
        }
        if(op.empty()) {
            l = r;
            r++;
            op.pb(l);
        }
        else {
            l = op.back();
        }
    }
    while(ops < op.size()) {
        res[op.front()] = ')';
        op.pop_front();
    }
    while(op.size()) {
        res[op.back()] = '(';
        op.pop_back();
    }
    
    answer();
}


signed main() { 
    fastio();
    solve();
}

Compilation message

zagrade.cpp: In function 'void solve()':
zagrade.cpp:54:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |         if(op.size() > ops) {
      |            ~~~~~~~~~~^~~~~
zagrade.cpp:67:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     while(ops < op.size()) {
      |           ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 4 ms 600 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 4 ms 556 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 556 KB Output is correct
5 Correct 4 ms 552 KB Output is correct
6 Correct 4 ms 612 KB Output is correct
7 Correct 5 ms 808 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 228 ms 536 KB Output is correct
3 Correct 506 ms 536 KB Output is correct
4 Correct 514 ms 536 KB Output is correct
5 Correct 499 ms 532 KB Output is correct
6 Correct 525 ms 596 KB Output is correct
7 Correct 463 ms 1572 KB Output is correct
8 Correct 475 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 496 ms 1636 KB Output is correct
3 Correct 549 ms 1076 KB Output is correct
4 Correct 490 ms 1392 KB Output is correct
5 Correct 526 ms 1356 KB Output is correct
6 Correct 474 ms 1152 KB Output is correct
7 Correct 485 ms 1628 KB Output is correct
8 Correct 506 ms 596 KB Output is correct