# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
381485 |
2021-03-25T08:29:17 Z |
kartel |
Zagrade (COI20_zagrade) |
C++14 |
|
1012 ms |
1588 KB |
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define M ll(1e9 + 7)
//#define M ll(998244353)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
#define eps (ld)1e-9
using namespace std;
typedef long long ll;
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef double ld;
typedef unsigned long long ull;
typedef short int si;
bool get(int l, int r) {
int x;
cout << "? " << l << " " << r << endl;
cin >> x;
return x;
}
int main()
{
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());;
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// in("toys.in");
// out("toys.out");
// in("input.txt");
// out("output.txt");
// cerr.precision(9); cerr << fixed;
// clock_t tStart = clock();
int n, q;
cin >> n >> q;
int last = 1;
string ans = "";
for (int i = 1; i <= n; i++) {
ans += "X";
}
vector <int> op;
int ccl = n / 2;
for (int i = 1; i <= n; i++) {
if (!sz(op)) {
op.pb(i);
continue;
}
bool is = get(op.back(), i);
if (!is) {
op.pb(i);
}
else {
ans[op.back() - 1] = '(';
ans[i - 1] = ')';
ccl--;
op.pop_back();
}
}
for (int i = 0; i < n; i++) {
if (ans[i] == 'X') {
if (!ccl) {
ans[i] = '(';
}
else {
ans[i] = ')';
ccl--;
}
}
}
cout << "! " << ans << endl;
}
/*
7
4 6 7 2 3 1 5
*/
Compilation message
zagrade.cpp: In function 'int main()':
zagrade.cpp:54:9: warning: unused variable 'last' [-Wunused-variable]
54 | int last = 1;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
8 ms |
364 KB |
Output is correct |
4 |
Correct |
6 ms |
364 KB |
Output is correct |
5 |
Correct |
10 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
7 |
Correct |
9 ms |
364 KB |
Output is correct |
8 |
Correct |
6 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
11 ms |
364 KB |
Output is correct |
3 |
Correct |
8 ms |
364 KB |
Output is correct |
4 |
Correct |
11 ms |
364 KB |
Output is correct |
5 |
Correct |
10 ms |
364 KB |
Output is correct |
6 |
Correct |
6 ms |
364 KB |
Output is correct |
7 |
Correct |
8 ms |
364 KB |
Output is correct |
8 |
Correct |
8 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
442 ms |
616 KB |
Output is correct |
3 |
Correct |
828 ms |
640 KB |
Output is correct |
4 |
Correct |
811 ms |
680 KB |
Output is correct |
5 |
Correct |
838 ms |
620 KB |
Output is correct |
6 |
Correct |
823 ms |
620 KB |
Output is correct |
7 |
Correct |
856 ms |
1048 KB |
Output is correct |
8 |
Correct |
800 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1012 ms |
1588 KB |
Output is correct |
3 |
Correct |
892 ms |
784 KB |
Output is correct |
4 |
Correct |
780 ms |
1020 KB |
Output is correct |
5 |
Correct |
961 ms |
800 KB |
Output is correct |
6 |
Correct |
803 ms |
1100 KB |
Output is correct |
7 |
Correct |
883 ms |
872 KB |
Output is correct |
8 |
Correct |
880 ms |
620 KB |
Output is correct |