結果

問題 No.6 使いものにならないハッシュ
ユーザー kk
提出日時 2014-10-29 13:36:28
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,367 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 75,040 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 23:03:06
合計ジャッジ時間 2,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

int mhash(int x) {
  while (x%10 != x) {
    int t = 0;
    for (int i = x; i != 0; i/=10) t += i%10;
    x = t;
  }
  return x;
}

int main() {
  int k, n;
  cin >> k >> n;
  bool not_prime[n+1];
  memset(not_prime, false, sizeof(not_prime));
  not_prime[1] = true;
  for (int i = 2; i <= n; i++) {
    for (int j = i+i; j <= n; j+=i) {
      not_prime[j] = true;
    }
  }

  //  for (int i = 0; i <= n; i++) cout << i << ": " << not_prime[i] << endl;

  vector <int> memo;
  for (int i = k; i <= n; i++) if (!not_prime[i]) memo.push_back(i);

   // for (int i = 0; i < memo.size(); i++) cout << mhash(memo[i]) << endl;
  int ans, maxi = 0;
  bool used[10]; memset(used, false, sizeof(used));
  for (int l = 0, r = 0; r <= memo.size(); r++) {
    if (used[mhash(memo[r])]) {
      while (mhash(memo[l]) != mhash(memo[r])) {
	used[mhash(memo[l])] = false;
	l++;
      }
      l++;
    }
    if (maxi <= r-l+1) {
      maxi = r-l+1;
      ans = memo[l];
    }
    used[mhash(memo[r])] = true;
  }

  cout << ans << endl;
}
0