結果

問題 No.6 使いものにならないハッシュ
ユーザー tkm2261tkm2261
提出日時 2017-06-30 02:45:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,211 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 149,556 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:06:11
合計ジャッジ時間 3,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 29 ms
4,348 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 7 ms
4,348 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 15 ms
4,352 KB
testcase_07 AC 9 ms
4,352 KB
testcase_08 AC 14 ms
4,348 KB
testcase_09 AC 7 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 6 ms
4,352 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 10 ms
4,348 KB
testcase_17 AC 22 ms
4,352 KB
testcase_18 AC 28 ms
4,348 KB
testcase_19 AC 22 ms
4,348 KB
testcase_20 AC 18 ms
4,348 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 20 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,352 KB
testcase_26 AC 22 ms
4,352 KB
testcase_27 AC 17 ms
4,352 KB
testcase_28 AC 10 ms
4,352 KB
testcase_29 AC 23 ms
4,348 KB
testcase_30 AC 19 ms
4,352 KB
testcase_31 AC 19 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

bool is_prime(int n){
  if (n < 2) return false;
  int i = 2;
  while (i * i <= n) {
    if( n % i == 0){
      return false;
    }
    i++;
  }
  return true;
}

int hashh(int v) {
	while(v>=10) v=v/10+v%10;
	return v;
}

int h[200200];

int main(){

  int K, N;
  cin >> K;
  cin >> N;
  FOR(i, K, N + 1) {
    if(is_prime(i)) {
      h[i] = hashh(i);
    } else {
      h[i] = -1;
    }
  }
  int max_cnt = -1;
  int max_int = -1;
  FOR(i, K, N + 1){
    if(h[i] == -1) continue;
    set<int> st;
    int cnt = 0;
    FOR(j, i, N + 1){
      if(h[j] == -1) continue;
      //cout << h[j] <<  " ";
      st.insert(h[j]);
      cnt++;
      if (st.size() != cnt) break;
    }
    cnt = st.size();
    //cout << endl;
    if(max_cnt <= cnt && i > max_int) {
      max_int = i;
    }
    max_cnt = max(max_cnt, cnt);

  }
  cout << max_int << endl;

  return 0;
}
0