結果
| 問題 |
No.515 典型LCP
|
| コンテスト | |
| ユーザー |
myanta
|
| 提出日時 | 2017-05-08 23:39:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,092 bytes |
| コンパイル時間 | 468 ms |
| コンパイル使用メモリ | 47,744 KB |
| 実行使用メモリ | 7,168 KB |
| 最終ジャッジ日時 | 2024-09-14 17:36:21 |
| 合計ジャッジ時間 | 2,960 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 RE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:57:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
57 | scanf("%s", p);
| ~~~~~^~~~~~~~~
main.cpp:63:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | scanf("%d%d%d", &m, &x, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
using ll=long long;
vector<char*> s;
vector<vector<int> > dp;
void swap(int& a, int& b)
{
int c;
c=a;
a=b;
b=c;
}
int lcp(int i, int j)
{
if(i<j) swap(i, j);
if(j>=dp[i].size()) dp[i].resize(j+1, -1);
else if(dp[i][j]>=0) return dp[i][j];
char *p, *q;
int k;
p=s[i];
q=s[j];
for(k=0;p[k] && p[k]==q[k];k++)
;
return dp[i][j]=k;
}
int main(void)
{
vector<char> buf;
char *p;
int i, j, k, n, m, x, d;
ll result;
while(scanf("%d", &n)==1)
{
dp.clear();
dp.resize(n);
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(i-1, j-1);
// printf("k=%d x=%d i=%d j=%d %lld\n", k, x, i, j, result);
}
printf("%lld\n", result);
/*
for(auto x: dp)
{
for(auto y: x) printf("%2d ", y);
printf("\n");
}
*/
}
return 0;
}
myanta