Submission #411959

# Submission time Handle Problem Language Result Execution time Memory
411959 2021-05-26T10:56:42 Z 최서현(#7464) Zagrade (COI20_zagrade) C++17
0 / 100
1 ms 200 KB
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n, q; cin >> n >> q;

    int L[n + 2], R[n + 2];
    for(int i = 0; i <= n + 1; ++i) L[i] = i - 1, R[i] = i + 1;
    string ans(n, ' ');

    int cnt = n;

    while(1)
    {
        bool flag = false;

        int pt = R[0];
        while(pt < n + 1)
        {
            int pt1 = R[pt];
            int pt2 = R[R[pt]];
            cout << "? " << pt << ' ' << pt1 << endl; cout.flush();
            int t; cin >> t;
            if(t)
            {
                flag = true;
                L[R[pt]] = L[pt];
                R[L[pt]] = R[pt];
                L[R[pt1]] = L[pt1];
                R[L[pt1]] = R[pt1];
                ans[pt - 1] = '(';
                ans[pt1 - 1] = ')';
                cnt -= 2;
            }
            pt = pt2;
        }

        if(!flag)
        {
            int cnt2 = 0;
            for(auto &c : ans) if(c == ' ')
            {
                if(cnt2 < cnt / 2) ++cnt2, c = ')';
                else c = '(';
            }
            break;
        }

        pt = R[R[0]];
        flag = false;
        while(pt < n + 1 && R[pt] < n + 1)
        {
            int pt1 = R[pt];
            int pt2 = R[R[pt]];
            cout << "? " << pt << ' ' << pt1 << endl; cout.flush();
            int t; cin >> t;
            if(t)
            {
                flag = true;
                L[R[pt]] = L[pt];
                R[L[pt]] = R[pt];
                L[R[pt1]] = L[pt1];
                R[L[pt1]] = R[pt1];
                ans[pt - 1] = '(';
                ans[pt1 - 1] = ')';
                cnt -= 2;
            }
            pt = pt2;
        }

        if(!flag)
        {
            int cnt2 = 0;
            for(auto &c : ans) if(c == ' ')
            {
                if(cnt2 < cnt / 2) ++cnt2, c = ')';
                else c = '(';
            }
            break;
        }
    }

    cout << ans << endl; cout.flush();
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Incorrect query ()
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Incorrect query )(
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Incorrect query ))((
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Incorrect query ))((
2 Halted 0 ms 0 KB -