結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
Humpty0904
|
| 提出日時 | 2016-06-15 04:53:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 760 bytes |
| コンパイル時間 | 729 ms |
| コンパイル使用メモリ | 43,648 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 16:33:40 |
| 合計ジャッジ時間 | 1,570 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <vector>
#include <algorithm>
#include <cstdio>
#define M 200000
using namespace std;
int _hash(int n){
for(;n>9;){
int s=0;
for(;n;n/=10)s+=n%10;
n=s;
}
return n;
}
int table[M+1],p[M/2];
int main(){
int i,j,n,m;
table[0]=table[1]=1;
for(i=2;i<=M;i++)if(!table[i])for(j=2*i;j<=M;j+=i)table[j]=1;
scanf("%d%d",&n,&m);
vector<int>lst;
vector<int>lst_val;
int result=0,result_max=0,result_val;
for(i=n;i<=m;i++)if(!table[i]){
int h=_hash(i);
for(;find(lst.begin(),lst.end(),h)!=lst.end();result--){
lst.erase(lst.begin());
lst_val.erase(lst_val.begin());
}
lst.push_back(h);
lst_val.push_back(i);
result++;
if(result_max<=result){
result_max=result;
result_val=lst_val[0];
}
}
printf("%d\n",result_val);
}
Humpty0904