結果
| 問題 | 
                            No.515 典型LCP
                             | 
                    
| コンテスト | |
| ユーザー | 
                             myanta
                         | 
                    
| 提出日時 | 2017-05-05 23:09:33 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 822 bytes | 
| コンパイル時間 | 403 ms | 
| コンパイル使用メモリ | 41,728 KB | 
| 実行使用メモリ | 10,624 KB | 
| 最終ジャッジ日時 | 2024-09-14 09:09:29 | 
| 合計ジャッジ時間 | 3,456 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 2 | 
| other | RE * 2 TLE * 1 -- * 12 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |                         scanf("%s", p);
      |                         ~~~~~^~~~~~~~~
main.cpp:49:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |                 scanf("%d%d%d", &m, &x, &d);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#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