結果

問題 No.2745 String Swap Battle
ユーザー hiikunZhiikunZ
提出日時 2024-04-20 21:56:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 1,964 bytes
コンパイル時間 2,607 ms
コンパイル使用メモリ 207,560 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-20 21:56:27
合計ジャッジ時間 4,138 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 7 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 193 ms
9,472 KB
testcase_13 AC 198 ms
9,584 KB
testcase_14 AC 185 ms
9,600 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 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++){
        bool ok = 0;
        for(char c = 'a';c <= 'z';c++){
            ll a = -1,b = -1;
            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;
                }
            }
            if(a != -1 && b != -1){
                if(a > b){
                    swap(S[i][a],S[i][b]);
                    ok = 1;
                    break;
                }
            }
        }
        if(!ok){
            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 << a << " " << b << endl;

        //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