結果

問題 No.6 使いものにならないハッシュ
ユーザー togatogatogatoga
提出日時 2015-08-23 15:56:41
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,432 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 152,320 KB
実行使用メモリ 87,712 KB
最終ジャッジ日時 2023-10-14 22:54:35
合計ジャッジ時間 13,688 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int sieve(int)’:
main.cpp:19:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 200010;
int K,N;
vector<int> prime;
bool flag[MAX_N];
int sieve(int N){
  memset(flag, true, sizeof(flag));
  for (int i = 2; i <= N; i++){
    if (flag[i]){
      if (K <= i)prime.push_back(i);
      for (int j = i + i; j <= N; j+= i){
	flag[j] = false;
      }
    }
  }
}

int calc(int num){

  while (true){
    int res = 0;
    while (num){
      res += num % 10;
      num /= 10;
    }
    if (res <= 9)return res;
    num = res;
  }
}

int main(){

  cin >> K >> N;
  sieve(N);
  vector<int> array;
  for (int i = 0; i < prime.size(); i++){
    array.push_back(calc(prime[i]));
  }
  int head = 0;
  int tail = 0;
  set<int> used;
  int ans = 0;
  int ansele = -1;
  // for (const auto &val : prime){
  //   printf("%02d ", val);
  // }
  // cout << endl;
  // for (const auto &val : array){
  //   printf("%02d ", val);

  // }
  // cout << endl;
  while (tail < array.size()){
    if (used.count(array[tail]) == 0){
      used.insert(array[tail++]);
      if (ans < (tail - head)){
	ans = tail - head;
	ansele = prime[head];
      }else if (ans == (tail - head) && ansele < prime[head]){
	ans = tail - head;
	ansele = prime[head];
      }
    }else{
      while (true){
	if (head == tail)break;
	if (array[head] == array[tail]){
	  used.erase(array[head++]);
	  break;
	}else{
	  used.erase(array[head++]);
	}
      }
    }

  }
  cout << ansele << endl;
}
0