結果

問題 No.6 使いものにならないハッシュ
ユーザー ransewhaleransewhale
提出日時 2018-07-14 01:10:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,059 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 168,704 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 23:12:17
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 3 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,356 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 3 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:70:17: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   70 |         cout << ans << endl;
      |                 ^~~
main.cpp:30:27: 備考: ‘ans’ はここで定義されています
   30 |         int k,n,i,j,p,m,t,ans,memo=0;
      |                           ^~~

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

int f(int x){
	return (x<10)?x:x%10+f(x/10);
}

bool isp[225816];
vector<P> v;

int main(void){
	int k,n,i,j,p,m,t,ans,memo=0;
	bool d[10];
	fill(isp,isp+225816,true);
	isp[1] = false;
	cin >> k >> n;
	for(i=2; i<=500; ++i){
		if(!isp[i]){
			continue;
		}
		for(j=i*2; j<=n; j+=i){
			isp[j] = false;
		}
	}
	for(i=k; i<=n; ++i){
		if(!isp[i]){
			continue;
		}
		p = i;
		while(p>9){
			p = f(p);
		}
		v.push_back(P(p,i));
	}
	m = v.l_ength();
	for(i=0; i<m; ++i){
		fill(d,d+10,false);
		t = min(m,i+10)-i;
		for(j=i; j<min(m,i+10); ++j){
			if(d[v[j].first]){
				t = j-i;
				break;
			}else{
				d[v[j].first] = true;
			}
		}
		if(memo <= t){
			ans = v[i].second;
			memo = t;
		}
	}
	cout << ans << endl;
	return 0;
}
0