Submission #80016

#TimeUsernameProblemLanguageResultExecution timeMemory
80016pzdbaDoktor (COCI17_doktor)C++14
80 / 100
98 ms20632 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...