結果

問題 No.6 使いものにならないハッシュ
ユーザー 0w10w1
提出日時 2016-11-21 21:15:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 5,000 ms
コード長 670 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 170,068 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:04:13
合計ジャッジ時間 5,143 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 186 ms
4,352 KB
testcase_03 AC 14 ms
4,352 KB
testcase_04 AC 30 ms
4,348 KB
testcase_05 AC 31 ms
4,348 KB
testcase_06 AC 92 ms
4,352 KB
testcase_07 AC 52 ms
4,352 KB
testcase_08 AC 82 ms
4,348 KB
testcase_09 AC 35 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 15 ms
4,352 KB
testcase_12 AC 102 ms
4,352 KB
testcase_13 AC 20 ms
4,348 KB
testcase_14 AC 35 ms
4,348 KB
testcase_15 AC 81 ms
4,348 KB
testcase_16 AC 69 ms
4,348 KB
testcase_17 AC 148 ms
4,348 KB
testcase_18 AC 178 ms
4,352 KB
testcase_19 AC 140 ms
4,348 KB
testcase_20 AC 113 ms
4,352 KB
testcase_21 AC 7 ms
4,348 KB
testcase_22 AC 130 ms
4,352 KB
testcase_23 AC 104 ms
4,348 KB
testcase_24 AC 119 ms
4,352 KB
testcase_25 AC 63 ms
4,352 KB
testcase_26 AC 153 ms
4,352 KB
testcase_27 AC 114 ms
4,348 KB
testcase_28 AC 54 ms
4,352 KB
testcase_29 AC 160 ms
4,348 KB
testcase_30 AC 128 ms
4,352 KB
testcase_31 AC 122 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int get_hash( int v ){
  if( v < 10 )
    return v;
  int u = 0;
  while( v )
    u += v % 10, v /= 10;
  return get_hash( u );
}

signed main(){
  int L, R; cin >> L >> R;
  vector< int > cnt( 10 );
  deque< int > dq;
  int maxlen = 0, ans = -1;
  for( int i = R; i >= L; --i ){
    int ng = i == 1;
    for( int j = 2; j * j <= i; ++j )
      ng |= i % j == 0;
    if( ng ) continue;
    int hv = get_hash( i );
    while( cnt[ hv ] )
      --cnt[ dq.back() ], dq.pop_back();
    ++cnt[ hv ], dq.emplace_front( hv );
    if( maxlen < dq.size() )
      maxlen = dq.size(), ans = i;
  }
  cout << ans << endl;
  return 0;
}
0