Submission #554309

# Submission time Handle Problem Language Result Execution time Memory
554309 2022-04-28T06:43:43 Z leaked Zagrade (COI20_zagrade) C++17
100 / 100
850 ms 1232 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<(x))
#define sz(x) (int)(x).size()
#define vec vector

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,q;
    cin>>n>>q;
    vec<int> st;
    st.pb(0);
    auto ask=[&](int l,int r){
        cout<<"? "<<l+1<<' '<<r+1<<endl;
        cout.flush();
        int x;
        cin>>x;
        return x;
    };
    string ans(n,'(');
    vec<int>cnt(2,0);
    ++cnt[0];
    for(int i=1;i<n;i++){
        if(sz(st) && ask(st.back(),i)){
            st.pop_back();ans[i]=')';
            ++cnt[1];
        }
        else st.pb(i),++cnt[0];
    }
    int need=n/2;
    int j=0;
    int how=cnt[0]-need;
//    cout<<cnt[0]
//    for(int i=0;i<)
    for(auto &z : st){
        if(!how) break;
        --how;
        --cnt[0];
        ++cnt[1];
        ans[z]=')';
    }
    assert(cnt[0]==need && cnt[1]==need);

    cout<<"! "<<ans;
    cout.flush();
    return 0;
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:43:9: warning: unused variable 'j' [-Wunused-variable]
   43 |     int j=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 4 ms 208 KB Output is correct
3 Correct 4 ms 208 KB Output is correct
4 Correct 11 ms 208 KB Output is correct
5 Correct 10 ms 208 KB Output is correct
6 Correct 8 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 11 ms 316 KB Output is correct
5 Correct 8 ms 208 KB Output is correct
6 Correct 9 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 9 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 376 ms 392 KB Output is correct
3 Correct 539 ms 412 KB Output is correct
4 Correct 636 ms 392 KB Output is correct
5 Correct 706 ms 404 KB Output is correct
6 Correct 644 ms 396 KB Output is correct
7 Correct 672 ms 832 KB Output is correct
8 Correct 739 ms 396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 714 ms 1232 KB Output is correct
3 Correct 602 ms 680 KB Output is correct
4 Correct 628 ms 796 KB Output is correct
5 Correct 759 ms 644 KB Output is correct
6 Correct 632 ms 828 KB Output is correct
7 Correct 665 ms 664 KB Output is correct
8 Correct 850 ms 396 KB Output is correct