結果
| 問題 | No.515 典型LCP |
| コンテスト | |
| ユーザー |
myanta
|
| 提出日時 | 2017-05-05 23:09:33 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 822 bytes |
| 記録 | |
| コンパイル時間 | 666 ms |
| コンパイル使用メモリ | 61,984 KB |
| 実行使用メモリ | 14,628 KB |
| 最終ジャッジ日時 | 2026-04-04 11:44:29 |
| 合計ジャッジ時間 | 8,825 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 RE * 2 TLE * 3 -- * 3 |
ソースコード
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
using ll=long long;
void swap(int& a, int& b)
{
int c;
c=a;
a=b;
b=c;
}
int lcp(char *p, char *q)
{
int i;
for(i=0;p[i] && p[i]==q[i];i++)
;
return i;
}
int main(void)
{
vector<char> buf;
vector<char*> s;
char *p;
int i, j, k, n, m, x, d;
ll result;
while(scanf("%d", &n)==1)
{
s.resize(n);
buf.resize(800000+100000);
p=&buf[0];
for(i=0;i<n;i++)
{
scanf("%s", p);
s[i]=p;
p+=strlen(s[i])+1;
}
result=0;
scanf("%d%d%d", &m, &x, &d);
for(k=0;k<m;k++)
{
i=(x/(n-1))+1;
j=(x%(n-1))+1;
if(i>j) swap(i, j);
else j++;
x=(x+d)%(n*(n-1));
result+=lcp(s[i-1], s[j-1]);
// printf("k=%d x=%d i=%d j=%d %lld\n", k, x, i, j, result);
}
printf("%lld\n", result);
}
return 0;
}
myanta