Submission #780468

# Submission time Handle Problem Language Result Execution time Memory
780468 2023-07-12T09:14:50 Z Owen11 Zagrade (COI20_zagrade) C++14
100 / 100
767 ms 1196 KB
#include <bits/stdc++.h>
using namespace std;

# define int long long
# define fir first
# define sec second
# define pb push_back

const int cnst = 2e5+5;
bool mutipletestcase = 0;
bool debug = 0;

string checker;

int find(int x, int y) {
    int temp = 0;
    for(int i = x-1; i<y; i++) {
        if(checker[i] == '(') temp++;
        else temp--;

        if(temp < 0) return 0;
    }
    
    return temp == 0;
}

int ask(int l, int r) {
    cout << "? " << l << " " << r << endl;
    int a;
    if(!debug) cin >> a;
    else a = find(l, r);
    return a;
}

void solve() {
    int n, q; cin >> n >> q;
    char ans[n+5]; // )) (( )(

    for(int i = 1; i<=n; i++) ans[i] = '*';

    if(debug) cin >> checker;

    stack<int> st;
    st.push(1); st.push(1);
    int fre = 0;

    for(int i = 2; i<=n; i++) {
        bool a = ask(st.top(), i);
        if(a) {
            ans[st.top()] = '(';
            ans[i] = ')';
            fre++;
            st.pop();
        }
        else st.push(i);
    }

    int need = n/2-fre;

    cout << "! ";

    for(int i = 1; i<=n; i++) {
        if(ans[i] == '*') {
            if(need) {
                need--; cout << ')';
            }
            else cout << '(';
        }
        else cout << ans[i];
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t = 1;
    if(mutipletestcase) cin >> t; 
    while(t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 5 ms 208 KB Output is correct
4 Correct 6 ms 208 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
6 Correct 8 ms 208 KB Output is correct
7 Correct 7 ms 320 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 8 ms 320 KB Output is correct
3 Correct 8 ms 208 KB Output is correct
4 Correct 8 ms 316 KB Output is correct
5 Correct 6 ms 312 KB Output is correct
6 Correct 9 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 505 ms 384 KB Output is correct
3 Correct 573 ms 396 KB Output is correct
4 Correct 634 ms 388 KB Output is correct
5 Correct 755 ms 392 KB Output is correct
6 Correct 614 ms 396 KB Output is correct
7 Correct 742 ms 900 KB Output is correct
8 Correct 542 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 641 ms 1196 KB Output is correct
3 Correct 377 ms 548 KB Output is correct
4 Correct 594 ms 836 KB Output is correct
5 Correct 683 ms 596 KB Output is correct
6 Correct 744 ms 764 KB Output is correct
7 Correct 704 ms 628 KB Output is correct
8 Correct 767 ms 396 KB Output is correct