結果
| 問題 |
No.2745 String Swap Battle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-13 23:14:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 199 ms / 2,000 ms |
| コード長 | 1,614 bytes |
| コンパイル時間 | 2,703 ms |
| コンパイル使用メモリ | 207,824 KB |
| 最終ジャッジ日時 | 2025-02-21 01:18:51 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#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;
}