Submission #1103948

#TimeUsernameProblemLanguageResultExecution timeMemory
1103948HiepVu217Difference (POI11_roz)C++17
30 / 100
541 ms14420 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 17; int n, f[N], ans; string s; vector <int> v, p[217]; void build (char a, char b) { int i = 0, j = 0; while (i < p[a].size() && j < p[b].size()) { if (p[a][i] < p[b][j]) { v.push_back(1); ++i; } else { v.push_back(-1); ++j; } } while (i < p[a].size()) { v.push_back(1); ++i; } while (j < p[b].size()) { v.push_back(-1); ++j; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; for (int i = 0; i < s.size(); ++i) { p[s[i]].push_back(i); } for (char a = 'a'; a <= 'z'; ++a) { if (!p[a].size()) { continue; } for (char b = 'a'; b <= 'z'; ++b) { if (a == b || !p[b].size()) { continue; } build (a, b); for (int i = 1; i <= v.size(); ++i) { f[i] = f[i - 1] + v[i - 1]; } int m = 0; bool ex = 0; for (int i = 1; i <= v.size(); ++i) { if (v[i - 1] == -1) { ex = 1; } if (ex) { m = min (m, f[i]); ans = max (ans, f[i] - m); } } v.clear(); } } cout << ans; }

Compilation message (stderr)

roz.cpp: In function 'void build(char, char)':
roz.cpp:10:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   10 |     while (i < p[a].size() && j < p[b].size())
      |                  ^
roz.cpp:10:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     while (i < p[a].size() && j < p[b].size())
      |            ~~^~~~~~~~~~~~~
roz.cpp:10:37: warning: array subscript has type 'char' [-Wchar-subscripts]
   10 |     while (i < p[a].size() && j < p[b].size())
      |                                     ^
roz.cpp:10:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     while (i < p[a].size() && j < p[b].size())
      |                               ~~^~~~~~~~~~~~~
roz.cpp:12:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   12 |         if (p[a][i] < p[b][j])
      |               ^
roz.cpp:12:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   12 |         if (p[a][i] < p[b][j])
      |                         ^
roz.cpp:23:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   23 |     while (i < p[a].size())
      |                  ^
roz.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while (i < p[a].size())
      |            ~~^~~~~~~~~~~~~
roz.cpp:28:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     while (j < p[b].size())
      |                  ^
roz.cpp:28:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while (j < p[b].size())
      |            ~~^~~~~~~~~~~~~
roz.cpp: In function 'int main()':
roz.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < s.size(); ++i)
      |                     ~~^~~~~~~~~~
roz.cpp:42:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |         p[s[i]].push_back(i);
      |               ^
roz.cpp:46:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   46 |         if (!p[a].size())
      |                ^
roz.cpp:52:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   52 |             if (a == b || !p[b].size())
      |                              ^
roz.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for (int i = 1; i <= v.size(); ++i)
      |                             ~~^~~~~~~~~~~
roz.cpp:63:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for (int i = 1; i <= v.size(); ++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...