結果

問題 No.2745 String Swap Battle
ユーザー hiikunZhiikunZ
提出日時 2024-04-20 21:50:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,932 bytes
コンパイル時間 2,727 ms
コンパイル使用メモリ 209,292 KB
実行使用メモリ 9,644 KB
最終ジャッジ日時 2024-04-20 21:50:33
合計ジャッジ時間 4,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,248 KB
testcase_01 AC 5 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 426 ms
9,436 KB
testcase_13 AC 406 ms
9,588 KB
testcase_14 AC 418 ms
9,644 KB
testcase_15 AC 10 ms
6,940 KB
testcase_16 AC 9 ms
6,944 KB
testcase_17 AC 10 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
constexpr ll MAX = 2000000000000000000;
constexpr ld PI = 3.14159265358979;
constexpr ll MOD = 0;//2024948111;
ld dotorad(ld K){ return PI * K / 180.0; }
ld radtodo(ld K){ return K * 180.0 / PI; }
mt19937 mt;
void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); }
int main(){
    ll N;
    cin >> N;
    vector<string> S(N);
    for(ll i = 0; i < N; i++) cin >> S[i];
    for(ll i = 0;i < N;i++){
        ll a = -1,b = -1;
        char c = 127;
        for(ll j = 0;j < (ll)S[i].size();j++){
            c = min(c,S[i][j]);
        }
        for(ll j = (ll)S[i].size() - 1;j >= 0;j--){
            if(S[i][j] == c){
                a = j;
                break;
            }
        }
        for(ll j = 0;j < (ll)S[i].size();j++){
            if(S[i][j] != c){
                b = j;
                break;
            }
        }
        
        //cerr << a << " " << b << endl;
        if(a != -1 && b != -1){
            if(a > b){
                swap(S[i][a],S[i][b]);
            }
            else{
                vector<ll> cnt(26);
                for(ll j = 0;j < (ll)S[i].size();j++){
                    cnt[S[i][j] - 'a']++;
                }
                bool ok = 0;
                for(ll j = 0;j < 26;j++){
                    if(cnt[j] >= 2) ok = 1;
                }
                if(!ok){
                    swap(S[i][(ll)S[i].size() - 1],S[i][(ll)S[i].size() - 2]);
                }
            }
        }
        cerr << S[i] << endl;
    }
    vector<string> T = S;
    sort(T.begin(),T.end());
    ll cnt = 0;
    for(ll i = 0;i < N;i++){
        if(S[i] == T[0]) cnt++;
    }
    for(ll i = 0;i < N;i++){
        if(S[i] == T[0]) cout << N + 1 - cnt << endl;
        else cout << 0 << endl;
    }
}
0