結果
問題 | No.2745 String Swap Battle |
ユーザー |
|
提出日時 | 2024-04-20 05:37:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 939 bytes |
コンパイル時間 | 2,405 ms |
コンパイル使用メモリ | 210,224 KB |
最終ジャッジ日時 | 2025-02-21 06:03:44 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/segtree> using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) using S = pair<char,int>; S op(S a,S b){ if(a.first!=b.first) return min(a,b); return max(a,b); } S e(){ return {'z'+1,-1}; } using segtree = atcoder::segtree<S,op,e>; vector<S> f(string s){ int n=s.size(); vector<S> rt(n); rep(i,n) rt.at(i)={s.at(i),i}; return rt; } int main(){ int n; cin>>n; vector<string> s(n); rep(i,n) cin>>s.at(i); for(auto &x:s){ segtree seg(f(x)); int m=x.size(); int flg=0; rep(i,m){ S a=seg.prod(i+1,m); if(x.at(i)>a.first){ swap(x.at(i),x.at(a.second)); flg=2; break; }else if(x.at(i)==a.first){ flg=1; } } if(!flg){ swap(x.at(m-1),x.at(m-2)); } } map<string,int> mp; for(auto x:s){ mp[x]++; } string mn=mp.begin()->first; rep(i,n){ if(mn==s.at(i)) cout<<n+1-mp.at(mn)<<"\n"; else cout<<"0\n"; } }