Submission #381335

# Submission time Handle Problem Language Result Execution time Memory
381335 2021-03-25T06:30:49 Z NONAME Zagrade (COI20_zagrade) C++17
100 / 100
1135 ms 1576 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 << endl;
}

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 10 ms 364 KB Output is correct
4 Correct 9 ms 364 KB Output is correct
5 Correct 11 ms 364 KB Output is correct
6 Correct 10 ms 364 KB Output is correct
7 Correct 9 ms 364 KB Output is correct
8 Correct 9 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 236 KB Output is correct
2 Correct 10 ms 364 KB Output is correct
3 Correct 9 ms 364 KB Output is correct
4 Correct 10 ms 364 KB Output is correct
5 Correct 8 ms 364 KB Output is correct
6 Correct 10 ms 364 KB Output is correct
7 Correct 10 ms 364 KB Output is correct
8 Correct 5 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 340 ms 620 KB Output is correct
3 Correct 782 ms 620 KB Output is correct
4 Correct 898 ms 620 KB Output is correct
5 Correct 1135 ms 620 KB Output is correct
6 Correct 974 ms 620 KB Output is correct
7 Correct 883 ms 1020 KB Output is correct
8 Correct 864 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 980 ms 1576 KB Output is correct
3 Correct 935 ms 1044 KB Output is correct
4 Correct 989 ms 1248 KB Output is correct
5 Correct 803 ms 876 KB Output is correct
6 Correct 991 ms 1156 KB Output is correct
7 Correct 913 ms 1004 KB Output is correct
8 Correct 909 ms 620 KB Output is correct