답안 #367726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367726 2021-02-18T06:27:16 Z arnold518 Zagrade (COI20_zagrade) C++14
100 / 100
1124 ms 7348 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N, Q;

map<pii, int> MM;

bool query(int l, int r)
{
	if(MM.find({l, r})!=MM.end()) return MM[{l, r}];
	printf("? %d %d\n", l, r);
	fflush(stdout);
	int t;
	scanf("%d", &t);
	MM[{l, r}]=t;
	return t;
}

char ans[MAXN+10];

int main()
{
	scanf("%d%d", &N, &Q);
	vector<int> V;

	for(int i=1; i<=N; i++)
	{
		if(V.empty()) V.push_back(i);
		else
		{
			int t=V.back();
			if(query(t, i))
			{
				ans[t]='(';
				ans[i]=')';
				V.pop_back();
			}
			else
			{
				V.push_back(i);
			}
		}
	}
	for(int i=0; i<V.size()/2; i++) ans[V[i]]=')';
	for(int i=V.size()/2; i<V.size(); i++) ans[V[i]]='(';

	printf("! %s\n", ans+1);
	fflush(stdout);
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i=0; i<V.size()/2; i++) ans[V[i]]=')';
      |               ~^~~~~~~~~~~
zagrade.cpp:51:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i=V.size()/2; i<V.size(); i++) ans[V[i]]='(';
      |                        ~^~~~~~~~~
zagrade.cpp: In function 'bool query(int, int)':
zagrade.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
zagrade.cpp: In function 'int main()':
zagrade.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%d%d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 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 9 ms 364 KB Output is correct
6 Correct 10 ms 384 KB Output is correct
7 Correct 6 ms 364 KB Output is correct
8 Correct 8 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 13 ms 524 KB Output is correct
3 Correct 11 ms 364 KB Output is correct
4 Correct 13 ms 512 KB Output is correct
5 Correct 9 ms 364 KB Output is correct
6 Correct 16 ms 364 KB Output is correct
7 Correct 13 ms 364 KB Output is correct
8 Correct 10 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 541 ms 3652 KB Output is correct
3 Correct 1025 ms 6720 KB Output is correct
4 Correct 1050 ms 6912 KB Output is correct
5 Correct 883 ms 6904 KB Output is correct
6 Correct 881 ms 7068 KB Output is correct
7 Correct 1008 ms 7112 KB Output is correct
8 Correct 989 ms 6768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 900 ms 7348 KB Output is correct
3 Correct 919 ms 6932 KB Output is correct
4 Correct 1066 ms 7108 KB Output is correct
5 Correct 1060 ms 7116 KB Output is correct
6 Correct 738 ms 7068 KB Output is correct
7 Correct 1124 ms 7084 KB Output is correct
8 Correct 1117 ms 6980 KB Output is correct