Submission #80037

# Submission time Handle Problem Language Result Execution time Memory
80037 2018-10-18T11:13:55 Z pzdba Doktor (COCI17_doktor) C++14
100 / 100
314 ms 92652 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
int a[500005];
int pref[500005], suff[500005];
vector<pipii> dp[3000005];

int main(){
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
		if(i == a[i]) pref[i] = 1;
		pref[i] += pref[i-1];
	}
	for(int i=n;i>=1;i--){
		if(i == a[i]) suff[i] = 1;
		suff[i] += suff[i+1];
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		int diff = a[i]-i;
		if(diff == 0) ans++;
		int s = 0, e = 0;
		if(diff < 0) s = i+diff, e = i;
		else s = i, e = i+diff;
		int le = e-s+1;
		diff += 2*i;
		diff += 1000000;
		dp[diff].emplace_back(pipii(le, pii(s, e)));
	}
	int st = a[1], en = a[1];
	for(int i=0;i<=3000000;i++){
		int sum = 0;
		sort(dp[i].begin(), dp[i].end());
		for(int j=0;j<dp[i].size();j++){
			int le = dp[i][j].first;
			int s = dp[i][j].second.first;
			int e = dp[i][j].second.second;
			sum++;

			if(ans < sum + pref[s-1] + suff[e+1]){
				ans = sum + pref[s-1] + suff[e+1];
				st = s;
				en = e;
			}
		}
	}
	printf("%d %d\n", a[st], a[en]);
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:37:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<dp[i].size();j++){
               ~^~~~~~~~~~~~~
doktor.cpp:38:8: warning: unused variable 'le' [-Wunused-variable]
    int le = dp[i][j].first;
        ^~
doktor.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
doktor.cpp:13: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 85 ms 70776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 70936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 70936 KB Output is correct
2 Correct 72 ms 71024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 71100 KB Output is correct
2 Correct 74 ms 71100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 71100 KB Output is correct
2 Correct 78 ms 71228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 71256 KB Output is correct
2 Correct 73 ms 71256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 71388 KB Output is correct
2 Correct 171 ms 80928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 80928 KB Output is correct
2 Correct 104 ms 80928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 314 ms 89636 KB Output is correct
2 Correct 230 ms 89636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 89636 KB Output is correct
2 Correct 182 ms 92652 KB Output is correct