Submission #82223

# Submission time Handle Problem Language Result Execution time Memory
82223 2018-10-29T14:24:02 Z thiago4532 Doktor (COCI17_doktor) C++17
100 / 100
297 ms 48184 KB
#include <bits/stdc++.h>

using namespace std;
const int maxn = 2*500010;
int v[maxn], pref[maxn], n;
vector<int> c[maxn];

inline int qq(int a, int b){
	return pref[b] - pref[a-1];
}

int main(){
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	
	for(int i=1;i<=n;i++){
		cin >> v[i<<1];
		v[i<<1] *= 2;
		
		int centro = (v[(i<<1)] + (i<<1))/2;
		c[centro].push_back(abs(centro - (i<<1)));
	}

	for(int i=1;i<=n;i++)
		if(v[i<<1] == (i<<1)) pref[i<<1] = 1;
	for(int i=1;i<=2*n;i++)
		pref[i] += pref[i-1];

	int ans=0, a, b;
	for(int i=1;i<=2*n;i++){
		sort(c[i].begin(), c[i].end());
		for(int j=0;j<c[i].size();j++){
			int qtd = j + 1 - qq(i-c[i][j], i+c[i][j]) + (!(i&1) && v[i] == i);

			if(qtd > ans){
				ans = qtd;
				a = i-c[i][j];
				b = i+c[i][j];
			}
		}
	}

	cout << v[a]/2 << " " << v[b]/2 << "\n";
	return 0;
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<c[i].size();j++){
               ~^~~~~~~~~~~~
doktor.cpp:43:30: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << v[a]/2 << " " << v[b]/2 << "\n";
                           ~~~^
doktor.cpp:43:13: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << v[a]/2 << " " << v[b]/2 << "\n";
          ~~~^
# Verdict Execution time Memory Grader output
1 Correct 30 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23976 KB Output is correct
2 Correct 24 ms 24052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 24128 KB Output is correct
2 Correct 23 ms 24128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 24256 KB Output is correct
2 Correct 23 ms 24256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 24256 KB Output is correct
2 Correct 23 ms 24256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 24416 KB Output is correct
2 Correct 97 ms 31440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 31440 KB Output is correct
2 Correct 47 ms 31440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 44476 KB Output is correct
2 Correct 150 ms 44476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 297 ms 44476 KB Output is correct
2 Correct 137 ms 48184 KB Output is correct