結果

問題 No.2745 String Swap Battle
ユーザー MZKiMZKi
提出日時 2024-04-21 15:49:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,768 bytes
コンパイル時間 4,716 ms
コンパイル使用メモリ 268,196 KB
実行使用メモリ 18,652 KB
最終ジャッジ日時 2024-04-21 15:49:53
合計ジャッジ時間 6,200 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
5,540 KB
testcase_01 AC 10 ms
5,664 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 14 ms
5,532 KB
testcase_07 AC 14 ms
5,536 KB
testcase_08 AC 15 ms
5,792 KB
testcase_09 AC 14 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 177 ms
18,400 KB
testcase_13 AC 181 ms
18,528 KB
testcase_14 AC 182 ms
18,652 KB
testcase_15 AC 15 ms
6,144 KB
testcase_16 AC 16 ms
6,016 KB
testcase_17 AC 16 ms
6,144 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 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();
            swap(vec[i][m-1], vec[i][m-2]);
            fin.push_back({vec[i], i});
            continue;
        }

        int mn = mod, idx = -1, f = false;
        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