結果
| 問題 | 
                            No.515 典型LCP
                             | 
                    
| コンテスト | |
| ユーザー | 
                             myanta
                         | 
                    
| 提出日時 | 2017-05-09 00:08:46 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,257 bytes | 
| コンパイル時間 | 561 ms | 
| コンパイル使用メモリ | 49,280 KB | 
| 実行使用メモリ | 7,168 KB | 
| 最終ジャッジ日時 | 2024-09-14 17:42:01 | 
| 合計ジャッジ時間 | 2,904 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 13 WA * 2 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:34: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
   69 |                         printf("%d\n", strlen(s[0]));
      |                                 ~^     ~~~~~~~~~~~~
      |                                  |           |
      |                                  int         size_t {aka long unsigned int}
      |                                 %ld
main.cpp:64:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |                         scanf("%s", s[i]);
      |                         ~~~~~^~~~~~~~~~~~
main.cpp:74:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   74 |                 scanf("%d%lld%d", &m, &x, &d);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include<cstdio>
#include<cstdlib>
#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(i<0 || j<0 || i>=dp.size())
{
	printf("Wrong number.\n");
	exit(0);
}
	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, d;
	ll x, 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++)
		{
			s[i]=p;
			scanf("%s", s[i]);
			p+=strlen(s[i])+1;
		}
		if(n<=1)
		{
			printf("%d\n", strlen(s[0]));
			continue;
		}
		result=0;
		scanf("%d%lld%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)%((ll)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