Submission #411978

# Submission time Handle Problem Language Result Execution time Memory
411978 2021-05-26T11:25:36 Z 최서현(#7464) Zagrade (COI20_zagrade) C++17
0 / 100
1235 ms 1144 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 && R[pt] < n + 1)
        {
            int pt1 = R[pt];
            int pt2 = R[R[pt]];

            while(pt > 0)
            {
                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;
                }
                else break;
                pt1 = pt2;
                pt = L[pt1];
                pt2 = R[pt1];
            }
            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 Correct 1 ms 200 KB Output is correct
2 Correct 1235 ms 200 KB Output is correct
3 Runtime error 8 ms 200 KB Execution killed with signal 13
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 3 ms 200 KB Output is correct
3 Runtime error 17 ms 200 KB Execution killed with signal 13
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Mismatch at position 1. Expected (, found )
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 607 ms 1144 KB Output is correct
3 Runtime error 1089 ms 1096 KB Execution killed with signal 13
4 Halted 0 ms 0 KB -