Submission #641961

# Submission time Handle Problem Language Result Execution time Memory
641961 2022-09-18T03:42:00 Z kebine Zagrade (COI20_zagrade) C++17
0 / 100
673 ms 648 KB
#include <bits/stdc++.h>
using namespace std;

int n, q;
char arr[100005];

int ask(int l, int r) {
    cout << "? " << l <<  " "  << r << endl;
    int ret;
    cin >> ret;
    return ret;
}

int main() {
    cin >> n >> q;
    int sz = -1;

    vector<pair<int, int> > v;
    int l = 1, r = 2;
    while(r <= n) {
        int ret = ask(l, r);
        if (ret) {
            arr[l] = '(';
            arr[r] = ')';
            pair<int, int> res = make_pair(l, r);
            while (sz >= 0 && v[sz].second >= res.first - 1) {
                v.pop_back();
                sz--;
            }

            if (sz >= 0) {
                r++;
                l--;
            }
            else if(l > 1) {
              r++;
              l--;
            }
            else {
                r+=2;
                l = r - 1;
            }

            sz++;
            v.push_back(res);
        }
        else {
            r++;
            l = r - 1;
        }
    }

    cout << "! ";

    for(int i = 1; i <= n; i++) {
        cout << arr[i];
    }
    cout << endl;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 10 ms 208 KB Output is correct
3 Incorrect 11 ms 300 KB Mismatch at position 1. Expected (, found
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Mismatch at position 1. Expected ), found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 673 ms 424 KB Output is correct
3 Incorrect 639 ms 648 KB Mismatch at position 1. Expected (, found
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Mismatch at position 1. Expected ), found
2 Halted 0 ms 0 KB -