結果

問題 No.2745 String Swap Battle
ユーザー kenken714kenken714
提出日時 2024-04-13 23:14:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 3,178 ms
コンパイル使用メモリ 208,584 KB
実行使用メモリ 10,088 KB
最終ジャッジ日時 2024-04-13 23:14:43
合計ジャッジ時間 5,152 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,812 KB
testcase_01 AC 7 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 6 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 195 ms
9,428 KB
testcase_13 AC 197 ms
10,088 KB
testcase_14 AC 230 ms
9,300 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 8 ms
6,944 KB
testcase_17 AC 8 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<string, ll>


ll n, ans[210000], cnt;
vector<P> s;
int main(){
    cin >> n;
    REP(i, n) {
        ll cnt[26] = {};
        string ss;
        cin >> ss;
        REP(j, ss.size()) cnt[ss[j] - 'a']++;
        bool ok = false;
        REP(j, ss.size()){
            cnt[ss[j] - 'a']--;
            REP(k, ss[j] - 'a'){
                if(cnt[k] > 0){
                    ok = true;
                    FORR(l, ss.size() - 1, j + 1){
                        if(k == ss[l] - 'a'){
                            swap(ss[j], ss[l]);
                            break;
                        }
                    }
                    break;
                }
            }
            if(ok)break;
        }
        if(!ok) {
            REP(j, ss.size()) cnt[ss[j] - 'a']++;
            REP(j, 26) {
                if(cnt[j] >= 2) ok = true;
            }
            if(!ok)swap(ss[ss.size() - 1], ss[ss.size() - 2]);
        }
        s.push_back(P(ss, i));
    }
    sort(ALL(s));
    REP(i, n){
        if(s[0].first == s[i].first)cnt++;
        else break;
    }
    REP(i, n){
        ans[s[i].second] = (s[0].first == s[i].first ? n + 1 - cnt : 0);
    }
    REP(i, n) cout << ans[i] << endl;
}
0