답안 #1002443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002443 2024-06-19T14:57:54 Z icebear Difference (POI11_roz) C++14
100 / 100
505 ms 14604 KB
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for(int i=a; i>=b; --i)
#define rep(i, n) for(int i=0; i<n; ++i)
#define red(i, n) for(int i=n-1; i>=0; --i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define task "differ"

const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll LLinf = 1e18 + 27092008;
const int N = 1e6 + 5;
int n;
string s;
vector<int> pos[26];

int maxSub(vector<int> &arr){
    int res = 0, Min1 = inf, Min2 = 0;
    FOR(i,1,(int)arr.size()-1){
        if (arr[i] == -1){
            Min1 = min(Min1, Min2);
            Min2 = inf;
        }
        arr[i] += arr[i-1];
        res = max(res, arr[i] - Min1);
        Min2 = min(Min2, arr[i]);
    }
    return res;
}

void solve(){
    cin >> n >> s;
    rep(i, n)
        pos[s[i] - 'a'].pb(i);
    int ans = 0;
    rep(i, 26)
        FOR(j,i+1,25){
            vector<int> arr(1, 0), tmp;
            int l=0, r=0;
            while(l < pos[i].size() && r < pos[j].size())
                if (pos[i][l] < pos[j][r]) arr.pb(+1), l++;
                else arr.pb(-1), r++;
            while(l < pos[i].size()) arr.pb(+1), l++;
            while(r < pos[j].size()) arr.pb(-1), r++;

            tmp = arr;
            for(int &v : tmp) v = -v; 
            ans = max({ans, maxSub(arr), maxSub(tmp)});
        }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int tc = 1;
//     cin >> tc;
    while(tc--) solve();
    return 0;
}

Compilation message

roz.cpp: In function 'void solve()':
roz.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             while(l < pos[i].size() && r < pos[j].size())
      |                   ~~^~~~~~~~~~~~~~~
roz.cpp:50:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             while(l < pos[i].size() && r < pos[j].size())
      |                                        ~~^~~~~~~~~~~~~~~
roz.cpp:53:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             while(l < pos[i].size()) arr.pb(+1), l++;
      |                   ~~^~~~~~~~~~~~~~~
roz.cpp:54:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             while(r < pos[j].size()) arr.pb(-1), r++;
      |                   ~~^~~~~~~~~~~~~~~
roz.cpp: In function 'int main()':
roz.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
roz.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 576 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 1112 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 496 ms 9524 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 284 ms 7320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 9164 KB Output is correct
2 Correct 295 ms 7672 KB Output is correct
3 Correct 212 ms 7112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 461 ms 9188 KB Output is correct
2 Correct 223 ms 13056 KB Output is correct
3 Correct 213 ms 8252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 409 ms 9068 KB Output is correct
2 Correct 255 ms 14604 KB Output is correct
3 Correct 280 ms 8068 KB Output is correct