Submission #116881

# Submission time Handle Problem Language Result Execution time Memory
116881 2019-06-14T03:22:48 Z nhimnam120 Doktor (COCI17_doktor) C++14
30 / 100
1000 ms 4188 KB
#include<bits/stdc++.h>
using namespace std;
long long inp[500005];
signed main()
{
	long long n;
	cin >> n;
	long long ans=0;
	for(int i=1;i<=n;i++){
		cin >> inp[i];
		if(inp[i]==i){
			ans++;
		}
	}
	long long mdx=ans;
	long long pos1,pos2;
	for(int i=1;i<=n-1;i++)
	{
		for(int j=i+1;j<=n;j++){
			long long pre=0;
			long long pas=0;
			for(int k=i;k<=j;k++){
				if(inp[k]==k){
					pre++;
				}
				if(inp[k]==j-(k-i))
				{
					pas++;
				}
			}
			long long now=ans-pre+pas;
			if(now>mdx){
				mdx=now;
				pos1=i;
				pos2=j;
			}
		}
	}
	if(mdx==ans){
		cout << inp[1]<< " " << inp[1];
		return 0;
	}
	else
	{
		cout << inp[pos1]<< " " << inp[pos2];
	}
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:45:38: warning: 'pos2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   cout << inp[pos1]<< " " << inp[pos2];
                                      ^
doktor.cpp:45:19: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   cout << inp[pos1]<< " " << inp[pos2];
                   ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 256 KB Output is correct
2 Correct 19 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 1024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 4188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 2528 KB Time limit exceeded
2 Halted 0 ms 0 KB -