結果

問題 No.2745 String Swap Battle
ユーザー GOTKAKO
提出日時 2024-04-20 14:26:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,524 bytes
コンパイル時間 2,898 ms
コンパイル使用メモリ 217,664 KB
最終ジャッジ日時 2025-02-21 06:35:26
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
vector<string> S(N);
vector<pair<string,int>> S2(N);
for(auto &s : S) cin >> s;
int idx = -1;
for(auto s : S){
idx++;
string t = s;
sort(t.begin(),t.end());
int n = s.size();
vector<vector<int>> C(26);
for(int i=1; i<n; i++) C.at(s.at(i)-'a').push_back(i);
if(t == s){
bool ok = false;
for(int i=0; i<26; i++){
if(C.at(i).size() <= 1) continue;
swap(s.at(C.at(i).at(0)),s.at(C.at(i).at(1)));
ok = true; break;
}
if(!ok) swap(s.at(n-1),s.at(n-2));
S2.at(idx) = {s,idx};
}
else{
for(int i=0; i<n; i++){
if(s.at(i) == t.at(i)) continue;
char c = 'z'+1; int pos = n;
for(int k=n-1; k>i; k--){
if(c > s.at(k)) c = s.at(k),pos = k;
}
swap(s.at(i),s.at(pos));
break;
}
S2.at(idx) = {s,idx};
}
}
sort(S2.begin(),S2.end());
int win = 0; string s0 = S2.at(0).first;
vector<bool> W(N);
for(int i=0; i<N; i++){
if(S2.at(i).first == s0) win++,W.at(S2.at(i).second) = true;
else break;
}
for(auto w : W){
if(w) cout << N+1-win << endl;
else cout << 0 << endl;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0