답안 #1107395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107395 2024-11-01T07:36:32 Z TrieTr Zagrade (COI20_zagrade) C++14
100 / 100
801 ms 1952 KB
#include<bits/stdc++.h>
using namespace std;
 
void local() {
	#define taskname ""
	if(fopen(taskname".inp", "r")) {
		freopen(taskname".inp", "r", stdin);
		freopen(taskname".out", "w", stdout);
	}
}
 
#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
template <class X, class Y> bool mini(X& x, Y y) {return x > y ? x = y, true : false;}
template <class X, class Y> bool maxi(X& x, Y y) {return x < y ? x = y, true : false;}
 
const int N = 1e6 + 5;
 
int n, q;
bool ask(int a, int b) {
	a++; b++;
	cout << "? " << a << ' ' << b << endl;
	bool ok; cin >> ok; return ok;
}
void answer(string s) {
	cout << "! " << s << endl;
	exit(0);
}
 
bool type[N];
 
int main() {
	fastio; local();
	cin >> n >> q;
	string s(n, '#'); stack<int>st; st.emplace(0);
	int cur = n;
	for(int i = 1; i < n; i++) {
		if(st.empty()) st.emplace(i);
		else {
			if(ask(st.top(), i)) {
				s[st.top()] = '('; s[i] = ')'; st.pop(); cur -= 2;
			}
			else st.emplace(i);
		}
	}
	for(int i = 0; i < n; i++) {
		if(s[i] == '#') {
			if(cur) s[i] = ')', cur -= 2;
			else s[i] = '(';
		}
	}
	answer(s);
}

Compilation message

zagrade.cpp: In function 'void local()':
zagrade.cpp:7:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
zagrade.cpp:8:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   freopen(taskname".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 8 ms 336 KB Output is correct
4 Correct 9 ms 336 KB Output is correct
5 Correct 8 ms 336 KB Output is correct
6 Correct 7 ms 336 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 7 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 9 ms 468 KB Output is correct
3 Correct 7 ms 336 KB Output is correct
4 Correct 8 ms 336 KB Output is correct
5 Correct 8 ms 336 KB Output is correct
6 Correct 6 ms 336 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 6 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 370 ms 552 KB Output is correct
3 Correct 732 ms 552 KB Output is correct
4 Correct 759 ms 556 KB Output is correct
5 Correct 801 ms 552 KB Output is correct
6 Correct 749 ms 556 KB Output is correct
7 Correct 713 ms 1952 KB Output is correct
8 Correct 761 ms 556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 782 ms 1432 KB Output is correct
3 Correct 775 ms 880 KB Output is correct
4 Correct 779 ms 1364 KB Output is correct
5 Correct 797 ms 1368 KB Output is correct
6 Correct 755 ms 1512 KB Output is correct
7 Correct 775 ms 1356 KB Output is correct
8 Correct 770 ms 556 KB Output is correct