제출 #690488

#제출 시각아이디문제언어결과실행 시간메모리
690488Kalashnikov성질 급한 지학이 (IZhO13_crazy)C++17
100 / 100
23 ms380 KiB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

int p[N];
int p1[N];

void solve(int tc) {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> p[i];
	}
	vector<int> vec;
	for(int i = 1; i <= n; i ++) {
		p1[1] = i;
		int cur = 1;
		for(int j = 2; j <= n; j ++) {
			if(cur == i) cur ++;
			p1[j] = cur;
			cur ++;
		}
		vector<int> u(n+1 , 0);
		u[p[1]] = 1;
		int ok = 1;
		for(int j = 2; j <= n; j ++) {
			if(u[p1[j]] == 0) {
				if(p[j] != p1[j]) {
					ok = 0;
					break;
				}
				u[p[j]] = 1;
			}
			else {
				if(u[p[j]] == 1) {
					ok = 0;
					break;
				}
				u[p[j]] = 1;
			}
		}
		if(ok) vec.push_back(i);
	}
	if(vec.size() == 1) {
		cout << vec[0] << '\n';
	}
	else cout << "0\n";
	
}
/*
*/
main() {
	file("crazy");
    ios;
    int tt = 1 , tc = 0;
    cin >> tt;
    while(tt --) {
        solve(++tc);
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

crazy.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main() {
      | ^~~~
crazy.cpp: In function 'int main()':
crazy.cpp:4:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
crazy.cpp:63:2: note: in expansion of macro 'file'
   63 |  file("crazy");
      |  ^~~~
crazy.cpp:4:77: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
crazy.cpp:63:2: note: in expansion of macro 'file'
   63 |  file("crazy");
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...