結果

問題 No.2745 String Swap Battle
ユーザー MZKiMZKi
提出日時 2024-04-21 15:56:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,923 bytes
コンパイル時間 5,512 ms
コンパイル使用メモリ 268,024 KB
実行使用メモリ 18,664 KB
最終ジャッジ日時 2024-04-21 15:56:35
合計ジャッジ時間 7,560 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,812 KB
testcase_01 AC 12 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 17 ms
6,944 KB
testcase_07 AC 15 ms
6,940 KB
testcase_08 AC 15 ms
6,944 KB
testcase_09 AC 15 ms
6,944 KB
testcase_10 AC 8 ms
6,944 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 200 ms
18,664 KB
testcase_13 AC 209 ms
18,532 KB
testcase_14 AC 204 ms
18,440 KB
testcase_15 AC 18 ms
6,940 KB
testcase_16 AC 18 ms
6,940 KB
testcase_17 AC 17 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n)cin >> s[i];

    vector<vector<int>> vec(n);
    rep(i, n)for(auto c : s[i])vec[i].push_back(c-'a');

    vector<pair<vector<int>, int>> fin;
    rep(i, n){
        vector<int> vec_ = vec[i];
        sort(all(vec_));
        
        int sw = -1;
        rep(j, vec[i].size()){
            if(vec[i][j] == vec_[j])continue;
            sw = j; break;
        }

        if(sw == -1){
            int m = vec[i].size();
            vector<int> cnt(26);
            rep(j, vec[i].size())cnt[vec[i][j]]++;

            bool f = false;
            rep(j, 26)if(cnt[j] >= 2)f = true;
            if(!f)swap(vec[i][m-1], vec[i][m-2]);
            fin.push_back({vec[i], i});
            continue;
        }

        int mn = mod, idx = -1;
        for(int j = sw+1; j < vec[i].size(); j++){
            if(mn >= vec[i][j]){
                mn = vec[i][j];
                idx = j;
            }
        }

        swap(vec[i][sw], vec[i][idx]);
        fin.push_back({vec[i], i});
    }

    sort(all(fin));
    vector<int> ans(n);
    
    int win = 0;
    while(win < n-1){
        if(fin[win].first == fin[win+1].first)win++;
        else break;
    }

    rep(i, win+1){
        ans[fin[i].second] = n - win;
    }

    rep(i, n)cout << ans[i] << endl;
}
0