結果
| 問題 |
No.515 典型LCP
|
| コンテスト | |
| ユーザー |
ixmel
|
| 提出日時 | 2017-05-06 12:43:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,601 bytes |
| コンパイル時間 | 1,255 ms |
| コンパイル使用メモリ | 101,308 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2024-09-14 13:50:34 |
| 合計ジャッジ時間 | 3,560 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 WA * 2 |
ソースコード
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<string,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
//http://tookunn.hatenablog.com/entry/2016/07/13/211148
//
//make:O(NlogN) update:muri query:O(1)
//
typedef int SegT;
const int defvalue=0;
class ST{//Sparse_table
public:
vector<SegT> A,log_table;
vector<vector<SegT> >table;
int n;
SegT combine(SegT a,SegT b){return min(a,b);}
ST(const vector<SegT> &in){
n=in.size();
A=in;
log_table=vector<SegT>(n+1);
loop(i,2,n+1)log_table[i]=log_table[i>>1]+1;
table=vector<vector<SegT> >(n,vector<SegT>(log_table[n]+1));
rep(i,n)table[i][0]=i;
for(int k=1;(1<<k)<=n;k++){
for(int i=0;i+(1<<k)<=n;i++){
int first=table[i][k-1];
int second=table[i+(1<<(k-1))][k-1];
if(A[first]<A[second])table[i][k]=first;
else table[i][k]=second;
}
}
}
SegT query(int s,int t){//[a,b] 0-index
// if(s>t)assert(1);
int d=t-s+1;
int k=log_table[d];
int out;
if(A[table[s][k]]<A[table[t-(1<<k)+1][k]])
out=table[s][k];
else out=table[t-(1<<k)+1][k];
// return out;
return A[out];
}
void tmp(){
rep(i,n){
rep(j,log_table[n]+1)cout<<" "<<table[i][j];
cout<<endl;
}
}
};
int main(){
int n;
cin>>n;
vp in(n);
rep(i,n)cin>>in[i].first;
rep(i,n)in[i].second=i;
sort(all(in));
vi lcp(n-1);
rep(i,n-1){
int co=0;
rep(j,min(in[i].first.size(),in[i+1].first.size()))if(in[i].first[j]==in[i+1].first[j])co++;else break;
lcp[i]=co;
}
ST st(lcp);
int m,x,d;
cin>>m>>x>>d;
vi to(n);
rep(i,n)to[in[i].second]=i;
ll out=0;
while(m--){
int i=x/(n-1);
int j=x%(n-1);
if(i>j)swap(i,j);
else j++;
i=to[i];j=to[j];
if(i>j)swap(i,j);
x=(x+d)%(n*(n-1));
out+=st.query(i,j-1);
}
cout<<out<<endl;
}
ixmel