Submission #80016

# Submission time Handle Problem Language Result Execution time Memory
80016 2018-10-18T08:36:50 Z pzdba Doktor (COCI17_doktor) C++14
80 / 100
98 ms 20632 KB
#include <bits/stdc++.h>
using namespace std;
int a[500005];
int dp[2000005];
int main(){
	int n;
	scanf("%d", &n);
	int ans = 0;
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
		int diff = a[i]-i;
		if(diff == 0) ans++;
		diff += 2*i;
		dp[diff]++;
	}
	int res = 0;
	int idx = 0;
	for(int i=0;i<=2000000;i++){
		if(dp[i] > res){
			res = dp[i];
			idx = i;
		}
	}
	if(res == 0 || res <= ans){
		printf("1 1\n");
		return 0;
	}
	int st = 1e9, en = 0;
	for(int i=1;i<=n;i++){
		int diff = a[i]-i;
		diff += 2*i;
		if(diff == idx){
			diff -= 2*i;
			if(diff < 0){
				st = min(st, i+diff);
				en = max(en, i);
			}
			else{
				st = min(st, i);
				en = max(en, i+diff);
			}
		}
	}
	printf("%d %d\n", a[st], a[en]);
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
doktor.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 740 KB Output is correct
2 Correct 6 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 740 KB Output is correct
2 Correct 6 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 828 KB Output is correct
2 Correct 6 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 948 KB Output is correct
2 Correct 43 ms 3884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 4348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 88 ms 12332 KB Output is correct
2 Correct 68 ms 12332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 15052 KB Output is correct
2 Correct 98 ms 20632 KB Output is correct