結果
問題 |
No.3109 Swap members
|
ユーザー |
![]() |
提出日時 | 2025-04-18 20:15:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 270 ms / 2,000 ms |
コード長 | 9,081 bytes |
コンパイル時間 | 8,551 ms |
コンパイル使用メモリ | 458,160 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2025-04-18 20:15:43 |
合計ジャッジ時間 | 17,200 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
コンパイルメッセージ
main.cpp:228:26: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’ 228 | vecll dijkstra(ll N,ll S,auto G){ | ^~~~ main.cpp:265:21: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’ 265 | void warshall_floyd(auto &dis){ | ^~~~ main.cpp:274:21: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’ 274 | vecll zahyouassyuku(auto X){ | ^~~~ main.cpp:335:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 335 | main(){ | ^~~~
ソースコード
//二分探索コピペ /* ll nibutan(){ //二分探索 ll ng=-1; ll ok=; while(ok-ng>1){ ll m=(ng+ok)/2; if()ok=m; else ng=m; } return ok; } */ #include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; using ll=long long; #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; // 任意長整数型 using Bint = mp::cpp_int; // 仮数部が10進数で1024桁の浮動小数点数型(TLEしたら小さくする) using Real = mp::number<mp::cpp_dec_float<1024>>; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define doubleketa(i) cout<<fixed<<setprecision(i); #define speedup std::cin.tie(0)->sync_with_stdio(0); #define _GLIBCXX_DEBUG //優先度付きキュー使って時間制限厳しい場合コメントアウト //#define int ll #define int_max 2147483647 #define int_min -2147483647 #define uint_max 4294967295 #define ll_max 9223372036854775807 #define ll_min -9223372036854775807 #define ull_max 18446744073709551615 #define rep(i,n) for(ll i=0;i<(n);i++) #define reps(i,n) for(ll i=1;i<=(n);i++) #define REP(i,j,n) for(ll i=(j);i<(n);i++) #define all(a) (a).begin(), (a).end() #define repc(i,n,A) rep(i,n)cin>>A[i] #define REPC(i,j,n,A) REP(i,j,n)cin>>A[i] #define repc2(i,n,A,B) rep(i,n)cin>>A[i]>>B[i] #define REPC2(i,j,n,A,B) REP(i,j,n)cin>>A[i]>>B[i] #define repc2vec(i,j,a,b,A) rep(i,a)rep(j,b)cin>>A[i][j] #define REPC2VEC(i,j,k,a,b,A) REP(i,k,a)REP(j,k,b)cin>>A[i][j] #define repair(i,n,A) rep(i,n)cin>>A[i].F>>A[i].S #define REPAIR(i,j,n,A) REP(i,j,n)cin>>A[i].F>>A[i].S #define ST(A) sort(all(A)) #define RV(A) reverse(all(A)) #define juufuku(A) A.erase(unique(all(A)),A.end()); #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define Endl endl #define F first #define S second #define yes(b) ((b)?"yes":"no") #define Yes(b) ((b)?"Yes":"No") #define YES(b) ((b)?"YES":"NO") #define TA(b) ((b)?"Takahashi":"Aoki") #define AB(b) ((b)?"Alice":"Bob") using veci=vector<int>; using veci2=vector<veci>; using veci3=vector<veci2>; using pi=pair<int,int>; using vecpi=vector<pi>; using vecpi2=vector<vecpi>; using vecll=vector<ll>; using vecst=vector<string>; using vecch=vector<char>; using vecll2=vector<vecll>; using vecst2=vector<vecst>; using pll=pair<ll,ll>; using vecch2=vector<vecch>; using vecpll=vector<pll>; using vecpll2=vector<vecpll>; using vecbo=vector<bool>; using vecbo2=vector<vecbo>; using vecdo=vector<double>; using vecdo2=vector<vecdo>; using pq=priority_queue<ll>; using pqp=priority_queue<pll>; using pqg=priority_queue<ll,vecll,greater<ll>>; using pqpg=priority_queue<pll,vecpll,greater<pll>>; template <typename T> inline T _gcd(T a,T b){return (b==0)?a:_gcd(b,a%b);}//最大公約数 template <typename T> inline T _lcm(T a,T b){return (a*b)/_gcd(a,b);}//最小公倍数 template <typename T> bool chmax(T &a,const T& b){ if(a<b){ a=b; return true; } return false; } template <typename T> bool chmin(T &a,const T& b){ if(a>b){ a=b; // aをbで更新 return true; } return false; } ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max((ll)b,a);} ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min((ll)b,a);} vecll DX={0,1,0,-1,1,1,-1,-1}; vecll DY={1,0,-1,0,1,-1,1,-1}; ll mod=998244353; ll modgyakugen=499122177; ll MOD=1000000007; ll INF=1e18; template<ll char_size,ll base> struct Trie{ struct Node{ // 頂点を表す構造体 vecll next; // 子の頂点番号を格納。存在しなければ-1 vecll accept; // 末端がこの頂点になる単語の word_id を保存 ll c; // base からの間隔をll型で表現したもの ll common; // いくつの単語がこの頂点を共有しているか Node(ll c_):c(c_),common(0){ next.assign(char_size,-1); } }; vector<Node>nodes; // trie木本体 ll root; Trie():root(0){ nodes.pb(Node(root)); } //単語の挿入 void insert(const string &word,ll word_id){ ll node_id=0; rep(i,word.size()){ ll c=(ll)(word[i]-base); ll &next_id=nodes[node_id].next[c]; if(next_id==-1){// 次の頂点が存在しなければ追加 next_id=(ll)nodes.size(); nodes.pb(Node(c)); } ++nodes[node_id].common; node_id = next_id; } ++nodes[node_id].common; nodes[node_id].accept.pb(word_id); } void insert(const string &word){ insert(word,nodes[0].common); } //単語とprefixの検索 bool search(const string &word,bool prefix=false){ ll node_id = 0; rep(i,word.size()){ ll c=(ll)(word[i]-base); ll &next_id=nodes[node_id].next[c]; if(next_id==-1){ // 次の頂点が存在しなければ終了 return false; } node_id = next_id; } return(prefix)?true:nodes[node_id].accept.size()>0; } //prefixを持つ単語が存在するかの検索 bool start_with(const string &prefix){ return search(prefix,true); } //挿入した単語の数 int count() const{ return(nodes[0].common); } //Trie木のノード数 int size() const{ return ((ll)nodes.size()); } }; ll randint(ll a,ll b){return a+rand()%(b-a+1);} double randouble(){return 1.0*rand()/RAND_MAX;} void debug(vecll A){rep(i,A.size())cerr<<A[i]<<" ";} void debug2(vecll2 A){ rep(i,A.size()){ debug(A[i]); cerr<<"\n"; } } ll nibutan(ll K,vecll& V){ //二分探索 ll ng=-1; ll ok=V.size(); while(ok-ng>1){ ll m=(ng+ok)/2; if(V[m]>=K)ok=m; else ng=m; } return ok; } vecpll soinsuubunkai(ll N){ vecpll res; for(ll a=2;a*a<=N;a++){ if(N%a!=0)continue; int ex=0;//指数 //割れる限り割る while(N%a==0){ ex++; N/=a; } //結果をpb res.pb({a,ex}); } //後に残った数について if(N!=1)res.pb({N,1}); return res; //N=6 {2,1} {3,1}(2^1*3^1)のようになる autoで受け取ろう } vecll yakusuurekkyo(ll N){ //答えを表す集合 vecll res; //各整数iがNの約数かどうかを調べる for (ll i=1;i*i<=N;++i){ //iがNの約数でない場合はスキップ if(N%i!=0)continue; //iは約数である res.pb(i); //N÷iも約数である(重複に注意) if(N/i!=i)res.pb(N/i); } //約数をソートして出力 ST(res); return res; } ll ketasuu(ll num){ ll digit=0; while(num!=0){ num/=10; digit++; } return digit; } vecll dijkstra(ll N,ll S,auto G){ vecll dis(N,ll_max); vecbo vis(N); pqpg Q; dis[S]=0; Q.push(mp(0,S)); while(!Q.empty()){ ll pos=Q.top().S;Q.pop(); if(vis[pos]==true)continue; vis[pos]=true; rep(i,G[pos].size()){ ll nex=G[pos][i].F; ll cost=G[pos][i].S; if(dis[nex]>dis[pos]+cost){ dis[nex]=dis[pos]+cost; Q.push(mp(dis[nex],nex)); } } } return dis; } vecll ruisekiwa(vecll V){ vecll A(V.size()+1); rep(i,V.size())A[i+1]=A[i]+V[i]; return A; } vecbo furui(ll N) { vecbo isprime(N+1,true); isprime[1]=false; for(ll p=2;p<=N;++p){ if(!isprime[p])continue; for(ll q=p*2;q<=N;q+=p){ isprime[q]=false; } } return isprime; } void warshall_floyd(auto &dis){ rep(k,dis.size()){ rep(i,dis.size()){ rep(j,dis.size()){ dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); } } } } vecll zahyouassyuku(auto X){ vecll x=X; ST(x); juufuku(x); vecll ans(X.size()); rep(i,X.size())ans[i]=lower_bound(all(x),X[i])-x.begin(); return ans; } vecll2 BFSgrid(vecst G,ll Sx,ll Sy,ll H,ll W){ vecll2 dis(H,vecll(W)); rep(i,H)rep(j,W)dis[i][j]=-1; dis[Sx][Sy]=0; queue<pll>Q; Q.push(mp(Sx,Sy)); while(!Q.empty()){ ll x=Q.front().F,y=Q.front().S; Q.pop(); rep(i,4){ ll nx=x+DX[i],ny=y+DY[i]; if(nx<0||nx>=H||ny<0||ny>=W)continue; if(dis[nx][ny]!=-1)continue; if(G[nx][ny]=='#')continue; Q.push(mp(nx,ny)); dis[nx][ny]=dis[x][y]+1; } } return dis; } /* encode: ランレングス圧縮を行う */ vector<pair<char, int>> encode(const string& str) { int n = (int)str.size(); vector<pair<char, int>> ret; for (int l = 0; l < n;) { int r = l + 1; for (; r < n && str[l] == str[r]; r++) {}; ret.push_back({str[l], r - l}); l = r; } return ret; } /* decode: ランレングス圧縮の復元を行う */ string decode(const vector<pair<char, int>>& code) { string ret = ""; for (auto p : code) { for (int i = 0; i < p.second; i++) { ret.push_back(p.first); } } return ret; } //ここからコード入力( ´・ω・` ) /** * 2月の目標 * 「丁寧なコードを書く」 * | * v * 3,4月の目標 * 「緑diff以下を安定させる」 */ main(){ ll A,B,ans=0; cin>>A>>B; string t; map<string,ll>M; rep(i,A){ cin>>t; M[t]=i; } rep(i,A){ cin>>t; ans+=((abs(i-M[t])%B)==0); } cout<<Yes(ans==A); }