답안 #100648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100648 2019-03-13T04:59:13 Z cki86201 성질 급한 지학이 (IZhO13_crazy) C++11
100 / 100
12 ms 384 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int main() {
	int T; scanf("%d", &T);
	rep(tt, T) {
		int N, p[1010];
		scanf("%d", &N);
		for(int i=1;i<=N;i++) scanf("%d", p+i);
		int ans = -1;
		for(int i=1;i<=N;i++) {
			int chk[1010] = {};
			chk[p[1]] = 1;
			int m = 1, ok = 1;
			for(int j=2;j<=N;j++) {
				if(m == i) ++m;
				if(chk[m] == 0 && p[j] != m) {
					ok = 0; break;
				}
				chk[p[j]] = 1;
				++m;
			}
			if(!ok) continue;
			if(ans == -1) ans = i;
			else ans = 0;
		}
		if(ans == -1) ans = 0;
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

crazy.cpp: In function 'int main()':
crazy.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int T; scanf("%d", &T);
         ~~~~~^~~~~~~~~~
crazy.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &N);
   ~~~~~^~~~~~~~~~
crazy.cpp:37:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i=1;i<=N;i++) scanf("%d", p+i);
                         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 8 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 10 ms 384 KB Output is correct
20 Correct 12 ms 384 KB Output is correct