結果

問題 No.2745 String Swap Battle
ユーザー cho435cho435
提出日時 2024-04-20 05:37:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 2,546 ms
コンパイル使用メモリ 209,860 KB
実行使用メモリ 6,924 KB
最終ジャッジ日時 2024-04-20 05:37:25
合計ジャッジ時間 3,344 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
6,788 KB
testcase_01 AC 21 ms
6,924 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 10 ms
6,924 KB
testcase_07 AC 9 ms
6,664 KB
testcase_08 AC 9 ms
6,796 KB
testcase_09 AC 9 ms
6,648 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 36 ms
6,400 KB
testcase_13 AC 43 ms
6,400 KB
testcase_14 AC 36 ms
6,528 KB
testcase_15 AC 7 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 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
	}
}
0