Submission #209743

# Submission time Handle Problem Language Result Execution time Memory
209743 2020-03-15T13:04:00 Z kapsel Difference (POI11_roz) C++14
100 / 100
331 ms 8464 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define LL long long 
#define ULL unsigned long long 
#define LD long double 

vector<int> wyst[26];
const int INF = 1e9 + 2137;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0; i<n; i++) {
		wyst[s[i]-97].push_back(i);
	}
	int wynik = 0;
	for(int a=0; a<26; a++) {
		for(int b=0; b<26; b++) {
			vector<int> ciag;
			int i = 0;
			int j = 0;
			int suma = 0;
			int minimum = INF;
			int w = 0;
			int sumap = 0;
			while(i<wyst[a].size() || j<wyst[b].size()) {
				int ob;
				if(i<wyst[a].size() && j<wyst[b].size()) {
					if(wyst[a][i]<wyst[b][j]) {
						ob = 1;
						i++;
					}
					else {
						ob = -1;
						j++;
					}
				}
				else if(i<wyst[a].size()) {
					i++;
					ob = 1;
				}
				else {
					j++;
					ob = -1;
				}
				suma+=ob;
				if(ob==-1) {
					minimum = min(minimum, sumap);
					sumap = suma;
				}
				w = max(w, suma-minimum);
			}
			wynik = max(wynik, w);
		}
	}
	cout<<wynik;
}

Compilation message

roz.cpp: In function 'int main()':
roz.cpp:33:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(i<wyst[a].size() || j<wyst[b].size()) {
          ~^~~~~~~~~~~~~~~
roz.cpp:33:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(i<wyst[a].size() || j<wyst[b].size()) {
                              ~^~~~~~~~~~~~~~~
roz.cpp:35:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(i<wyst[a].size() && j<wyst[b].size()) {
        ~^~~~~~~~~~~~~~~
roz.cpp:35:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(i<wyst[a].size() && j<wyst[b].size()) {
                            ~^~~~~~~~~~~~~~~
roz.cpp:45:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     else if(i<wyst[a].size()) {
             ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1144 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 331 ms 8464 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 191 ms 6416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 330 ms 7956 KB Output is correct
2 Correct 256 ms 7080 KB Output is correct
3 Correct 77 ms 5908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 8340 KB Output is correct
2 Correct 112 ms 6532 KB Output is correct
3 Correct 87 ms 6804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 8080 KB Output is correct
2 Correct 100 ms 7048 KB Output is correct
3 Correct 90 ms 6804 KB Output is correct