結果
問題 | No.6 使いものにならないハッシュ |
ユーザー | tottoripaper |
提出日時 | 2014-11-16 02:07:56 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 29 ms / 5,000 ms |
コード長 | 1,208 bytes |
コンパイル時間 | 525 ms |
コンパイル使用メモリ | 67,680 KB |
実行使用メモリ | 4,352 KB |
最終ジャッジ日時 | 2023-10-14 22:47:13 |
合計ジャッジ時間 | 2,214 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 1 ms
4,352 KB |
testcase_02 | AC | 29 ms
4,348 KB |
testcase_03 | AC | 4 ms
4,348 KB |
testcase_04 | AC | 7 ms
4,348 KB |
testcase_05 | AC | 7 ms
4,352 KB |
testcase_06 | AC | 15 ms
4,352 KB |
testcase_07 | AC | 9 ms
4,348 KB |
testcase_08 | AC | 14 ms
4,352 KB |
testcase_09 | AC | 6 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,352 KB |
testcase_11 | AC | 5 ms
4,352 KB |
testcase_12 | AC | 18 ms
4,348 KB |
testcase_13 | AC | 4 ms
4,352 KB |
testcase_14 | AC | 6 ms
4,352 KB |
testcase_15 | AC | 15 ms
4,348 KB |
testcase_16 | AC | 12 ms
4,352 KB |
testcase_17 | AC | 22 ms
4,348 KB |
testcase_18 | AC | 29 ms
4,352 KB |
testcase_19 | AC | 22 ms
4,348 KB |
testcase_20 | AC | 18 ms
4,352 KB |
testcase_21 | AC | 3 ms
4,348 KB |
testcase_22 | AC | 21 ms
4,348 KB |
testcase_23 | AC | 18 ms
4,348 KB |
testcase_24 | AC | 19 ms
4,348 KB |
testcase_25 | AC | 11 ms
4,348 KB |
testcase_26 | AC | 24 ms
4,348 KB |
testcase_27 | AC | 18 ms
4,348 KB |
testcase_28 | AC | 11 ms
4,348 KB |
testcase_29 | AC | 25 ms
4,352 KB |
testcase_30 | AC | 21 ms
4,348 KB |
testcase_31 | AC | 20 ms
4,348 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:61:11: warning: ‘first’ may be used uninitialized in this function [-Wmaybe-uninitialized] printf("%d\n", first); ~~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> int isPrime(int x){ if(x == 1){return false;} for(int i=2;i*i<=x;i++){ if(x % i == 0){return false;} } return true; } int hash(int x){ std::string s = std::to_string(x); while(s.size() > 1){ int sum = 0; for(auto c : s){sum += c - '0';} s = std::to_string(sum); } return s[0] - '0'; } int main(){ int K, N; scanf("%d %d", &K, &N); std::vector<int> primes; for(int i=K;i<=N;i++){ if(isPrime(i)){primes.push_back(i);} } int p_length = primes.size(); std::vector<int> hs; for(int i=0;i<p_length;i++){ hs.push_back(hash(primes[i])); } int maxLength = 0, first; int table[10]; std::fill(table, table+10, 0); for(int i=0,j=0;i<p_length;){ while(j<p_length && table[hs[j]] == 0){ table[hs[j]] += 1; j += 1; } if(j-i >= maxLength){ maxLength = j-i; first = primes[i]; } table[hs[i]] -= 1; i += 1; } printf("%d\n", first); }