Submission #1106816

# Submission time Handle Problem Language Result Execution time Memory
1106816 2024-10-31T05:38:39 Z 0pt1mus23 Zagrade (COI20_zagrade) C++14
100 / 100
775 ms 1904 KB
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
#define int long long int
#define ins insert      
#define pb push_back
// #define endl '\n'
#define putr(x) cout<<x<<endl;return; 
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 5e5 +5, inf = INT_MAX, LL = 30;

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

void rush(){
    int n,q;
    cin>>n>>q;
    vector<char> ans(n+10,'_');
    stack<int> st;
    for(int i=1;i<=n;i++){
        if(st.empty()){
            st.push(i);
        }
        else{
            int x = st.top();
            if(ask(x,i)){
                ans[x]='(';
                ans[i]=')';
                st.pop();
            }
            else{
                st.push(i);
            }
        }
    }
    int qal =0;
    for(int i=1;i<=n;i++){
        if(ans[i]=='_'){
            qal++;
        }
    }
    qal/=2;
    for(int i = n;i>=1;i--){
        if(ans[i]=='_'){
            if(qal){
                qal--;
                ans[i]='(';
            }
            else{
                ans[i]=')';
            }
        }
    }
    string res="";
    for(int i=1;i<=n;i++) res+=ans[i];
    cout<<"! "<<res<<endl;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int tt = 1; 
    // cin>>tt;

    while(tt--){
        rush();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 4 ms 452 KB Output is correct
3 Correct 8 ms 592 KB Output is correct
4 Correct 8 ms 336 KB Output is correct
5 Correct 9 ms 584 KB Output is correct
6 Correct 10 ms 336 KB Output is correct
7 Correct 6 ms 336 KB Output is correct
8 Correct 9 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 7 ms 460 KB Output is correct
3 Correct 7 ms 336 KB Output is correct
4 Correct 9 ms 592 KB Output is correct
5 Correct 10 ms 456 KB Output is correct
6 Correct 8 ms 460 KB Output is correct
7 Correct 7 ms 336 KB Output is correct
8 Correct 6 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 336 ms 796 KB Output is correct
3 Correct 651 ms 796 KB Output is correct
4 Correct 713 ms 812 KB Output is correct
5 Correct 722 ms 808 KB Output is correct
6 Correct 721 ms 800 KB Output is correct
7 Correct 775 ms 1336 KB Output is correct
8 Correct 763 ms 800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 743 ms 1904 KB Output is correct
3 Correct 757 ms 1444 KB Output is correct
4 Correct 748 ms 1452 KB Output is correct
5 Correct 773 ms 1204 KB Output is correct
6 Correct 750 ms 1388 KB Output is correct
7 Correct 769 ms 1256 KB Output is correct
8 Correct 771 ms 800 KB Output is correct