Submission #976849

# Submission time Handle Problem Language Result Execution time Memory
976849 2024-05-07T07:42:55 Z efedmrlr Zagrade (COI20_zagrade) C++17
71 / 100
498 ms 1784 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;
    res[1] = '(';
    vector<int> op;
    op.pb(1);
    for(int r = 2; r <= n; ) {
        bool x = query(l, r);
        if(x) {
            res[r] = ')';
            op.pop_back();
        }
        else {
            res[r] = '(';
            op.pb(r);
        }
        r++;
        if(op.empty()) {
            l = r;
            r++;
            res[l] = '(';
            op.pb(l);
        }
        else {
            l = op.back();
        }
    }

    answer();
}


signed main() { 
    fastio();
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 552 KB Output is correct
3 Correct 4 ms 552 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 4 ms 552 KB Output is correct
8 Correct 4 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 236 ms 540 KB Output is correct
3 Correct 477 ms 600 KB Output is correct
4 Correct 471 ms 540 KB Output is correct
5 Correct 459 ms 536 KB Output is correct
6 Correct 457 ms 536 KB Output is correct
7 Correct 473 ms 1784 KB Output is correct
8 Correct 498 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -