# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
712497 |
2023-03-18T21:56:36 Z |
noedit |
Zagrade (COI20_zagrade) |
C++17 |
|
897 ms |
1344 KB |
#include <bits/stdc++.h>
//#include <quadmath.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#define sz(x) (int)x.size()
//#define sqr(x) x*x
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
using namespace std;
//using namespace __gnu_pbds;
#define int long long
//#define ld long double
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
bool ask(int l, int r)
{
cout << "? " << l << " " << r << endl;
int b;
cin >> b;
return b;
}
const int MAXN = 1e5 + 10;
bool check[MAXN];
char ans[MAXN];
int lt[MAXN], rt[MAXN];
void solve()
{
int n, k;
cin >> n >> k;
stack<int> st;
fill(ans, ans + n + 1, '#');
for (int i = 1; i <= n; i++)
{
if (st.empty())
{
st.push(i);
}
else
{
int res = ask(st.top(), i);
if (res)
{
ans[st.top()] = '(';
ans[i] = ')';
st.pop();
}
else
{
st.push(i);
}
}
}
int cnt = 0;
for (int i = 1; i <= n; i++)
{
if (ans[i] == '#')
{
if (cnt < st.size() / 2) ans[i] = ')', cnt++;
else ans[i] = '(';
}
}
cout << "! ";
for (int i = 1; i <= n; i++) cout << ans[i];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}
/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10
*/
/*
2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7
*/
/*
1 1 1
100000000 1 1 1
1 1
*/
/*
4 4
1 2 1 3
1 1
1 2
1 3
1 4
*/
Compilation message
zagrade.cpp: In function 'void solve()':
zagrade.cpp:67:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::stack<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | if (cnt < st.size() / 2) ans[i] = ')', cnt++;
| ~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
208 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
8 ms |
208 KB |
Output is correct |
6 |
Correct |
9 ms |
208 KB |
Output is correct |
7 |
Correct |
10 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
9 ms |
332 KB |
Output is correct |
3 |
Correct |
11 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
6 ms |
336 KB |
Output is correct |
6 |
Correct |
9 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
336 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
291 ms |
408 KB |
Output is correct |
3 |
Correct |
651 ms |
416 KB |
Output is correct |
4 |
Correct |
516 ms |
416 KB |
Output is correct |
5 |
Correct |
715 ms |
404 KB |
Output is correct |
6 |
Correct |
830 ms |
404 KB |
Output is correct |
7 |
Correct |
862 ms |
892 KB |
Output is correct |
8 |
Correct |
795 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
771 ms |
1344 KB |
Output is correct |
3 |
Correct |
848 ms |
764 KB |
Output is correct |
4 |
Correct |
821 ms |
760 KB |
Output is correct |
5 |
Correct |
468 ms |
704 KB |
Output is correct |
6 |
Correct |
897 ms |
968 KB |
Output is correct |
7 |
Correct |
625 ms |
688 KB |
Output is correct |
8 |
Correct |
723 ms |
416 KB |
Output is correct |