結果

問題 No.6 使いものにならないハッシュ
ユーザー char134217728char134217728
提出日時 2017-08-19 03:12:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,176 bytes
コンパイル時間 1,476 ms
コンパイル使用メモリ 150,028 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 23:08:22
合計ジャッジ時間 2,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 10 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 4 ms
4,352 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 4 ms
4,352 KB
testcase_08 AC 5 ms
4,356 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 3 ms
4,352 KB
testcase_12 AC 7 ms
4,352 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 6 ms
4,352 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 7 ms
4,352 KB
testcase_18 AC 10 ms
4,348 KB
testcase_19 AC 7 ms
4,348 KB
testcase_20 AC 7 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 7 ms
4,352 KB
testcase_23 AC 7 ms
4,352 KB
testcase_24 AC 7 ms
4,352 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 8 ms
4,372 KB
testcase_27 AC 6 ms
4,348 KB
testcase_28 AC 5 ms
4,352 KB
testcase_29 AC 9 ms
4,348 KB
testcase_30 AC 8 ms
4,352 KB
testcase_31 AC 8 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:37:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
 main(){
      ^
main.cpp: In function ‘int main()’:
main.cpp:64:11: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   cout << ans << endl;
           ^~~

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;

vi pl;
bool is_prime(int a){
  if(a < 2)return false;
  for(vi::iterator itr = pl.begin(); itr != pl.end(); itr++){
    if(*itr * *itr > a)break;
    if(a % (*itr) == 0)return false;
  }
  return true;
}
int to_h(int a){
  if(a < 10)return a;
  while(a > 10){
    int s = 0;
    while(a > 0){
      s += a % 10;
      a /= 10;
    }
    a = s;
  }
  return a;
}
queue<int> q;
bool z[10];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 2, 501){
    if(is_prime(i))pl.pb(i);
  }
  int maxl = 0, ans;
  int k, n;
  cin >> k >> n;
  FORR(i, n, k){
    if(!is_prime(i))continue;
    int h = to_h(i);
    if(z[h]){
      while(true){
        int f = q.front();
        q.pop();
        z[f] = false;
        if(f == h)break;
      }
    }
    q.push(h);
    z[h] = true;
    if(maxl < q.size()){
      maxl = q.size();
      ans = i;
    }
  }
  cout << ans << endl;
}
0