Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:367077216")
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <map>
- #include <queue>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- #define pii pair<int, int>
- #define F first
- #define S second
- #define all(x) (x).begin(),(x).end()
- #define pb push_back
- #define pop pop_back
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- int n;
- cin >> n;
- vector<int> v = { 1 };
- vector<char> a(n + 1, '-');
- a[1] = '(';
- int f = 1, last = 1;
- while (last < n && f < n) {
- if (v.empty()) {
- a[f] = '(';
- last = f;
- v.push_back(f);
- }
- else {
- cout << "? " << f << " " << last + 1 << "\n";
- fflush(stdout);
- string s;
- cin >> s;
- if (s == "Yes") {
- a[last + 1] = ')';
- v.pop_back();
- if (!v.empty()) {
- f = v.back();
- last += 1;
- }
- else {
- f = last + 2;
- }
- }
- else {
- v.push_back(last + 1);
- a[last + 1] = '(';
- f = last + 1;
- last += 1;
- }
- }
- }
- cout << "! ";
- for (int i = 1; i <= n; ++i)
- cout << a[i];
- cout << "\n";
- fflush(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement