Submission #381333

# Submission time Handle Problem Language Result Execution time Memory
381333 2021-03-25T06:30:00 Z NONAME Zagrade (COI20_zagrade) C++17
100 / 100
982 ms 1376 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, const T b) {a = min(a, b); return (a == b);}
template <typename T> inline bool chmax(T& a, const T b) {a = max(a, b); return (a == b);}

int n, q;
string s;
vector <int> vc;

inline void cls() {}

int ask(int x, int y) {
    cout << "? " << (x + 1) << " " << (y + 1) << endl;
    cin >> x;
    return x;
}

void solve() {
    cls();

    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        s += '?';
    }

    for (int i = 0; i < n; ++i) {
        if (vc.empty()) {
            vc.push_back(i);
        } else {
            int x = ask(vc.back(), i);

            if (x) {
                s[vc.back()] = '(';
                s[i] = ')';
                vc.pop_back();
            } else {
                vc.push_back(i);
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        cnt += (s[i] == '?');
    }

    assert(!(cnt & 1));

    int cl = (cnt >> 1);
    for (int i = 0; i < n; ++i) {
        if (s[i] == '?') {
            if (cl) {
                --cl;
                s[i] = ')';
            } else {
                s[i] = '(';
            }
        }
    }

    cout << "! " << s << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    int t = 1;
    #ifdef _LOCAL
        system("color a");
//        freopen("in.txt", "r", stdin);
//        cin >> t;
    #endif

//    for (int i = 1; i <= t; ++i) {
//        cerr << "Case #" << i << ": \n";
        solve();
//        cerr << "\n";
//    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 12 ms 364 KB Output is correct
4 Correct 11 ms 364 KB Output is correct
5 Correct 15 ms 512 KB Output is correct
6 Correct 16 ms 364 KB Output is correct
7 Correct 9 ms 364 KB Output is correct
8 Correct 11 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 10 ms 364 KB Output is correct
3 Correct 10 ms 364 KB Output is correct
4 Correct 14 ms 364 KB Output is correct
5 Correct 14 ms 364 KB Output is correct
6 Correct 9 ms 364 KB Output is correct
7 Correct 12 ms 364 KB Output is correct
8 Correct 12 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 437 ms 620 KB Output is correct
3 Correct 863 ms 620 KB Output is correct
4 Correct 816 ms 620 KB Output is correct
5 Correct 736 ms 640 KB Output is correct
6 Correct 842 ms 620 KB Output is correct
7 Correct 816 ms 1100 KB Output is correct
8 Correct 929 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 857 ms 1372 KB Output is correct
3 Correct 687 ms 1008 KB Output is correct
4 Correct 966 ms 1184 KB Output is correct
5 Correct 760 ms 1136 KB Output is correct
6 Correct 982 ms 1376 KB Output is correct
7 Correct 678 ms 1004 KB Output is correct
8 Correct 935 ms 620 KB Output is correct