답안 #781303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781303 2023-07-13T02:23:34 Z devariaota Zagrade (COI20_zagrade) C++17
100 / 100
744 ms 800 KB
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long, long long>

int n,q,sisa;
stack<int> st;
char s[100069];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int i,j;
    cin>>n>>q;
    sisa = n/2;
    for(i=1;i<=n and q;i++)
    {
        if(st.empty())
        {
            st.push(i);
            continue;
        }
        cout<<"? "<<st.top()<<" "<<i<<'\n';
        cout.flush();
        bool valid;
        cin>>valid;
        if(valid)
        {
            s[st.top()] = '(';
            s[i] = ')';
            sisa--;
            st.pop();
        }
        else
        {
            st.push(i);
        }
        q--;
    }
    for(j=i;j<=n;j++) st.push(j);
    while(!st.empty())
    {
        int x = st.top();
        st.pop();
        if(sisa)
        {
            s[x] = '(';
            sisa--;
        }
        else
        {
            s[x] = ')';
        }
    }
    cout<<"! ";
    for(i=1;i<=n;i++)
    {
        cout<<s[i];
        if(i == n)
        {
            cout<<'\n';
        }
    }
    // )())(()(
}
# 결과 실행 시간 메모리 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 5 ms 208 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 8 ms 208 KB Output is correct
7 Correct 7 ms 208 KB Output is correct
8 Correct 5 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 4 ms 324 KB Output is correct
5 Correct 5 ms 208 KB Output is correct
6 Correct 9 ms 320 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 405 ms 356 KB Output is correct
3 Correct 543 ms 468 KB Output is correct
4 Correct 443 ms 444 KB Output is correct
5 Correct 744 ms 612 KB Output is correct
6 Correct 487 ms 472 KB Output is correct
7 Correct 685 ms 704 KB Output is correct
8 Correct 590 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 461 ms 800 KB Output is correct
3 Correct 677 ms 576 KB Output is correct
4 Correct 636 ms 604 KB Output is correct
5 Correct 626 ms 720 KB Output is correct
6 Correct 712 ms 592 KB Output is correct
7 Correct 387 ms 592 KB Output is correct
8 Correct 729 ms 444 KB Output is correct