結果

問題 No.6 使いものにならないハッシュ
ユーザー 夜
提出日時 2020-09-29 03:50:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,309 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 101,780 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:27:01
合計ジャッジ時間 2,389 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 5 ms
4,352 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 4 ms
4,352 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,352 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 4 ms
4,352 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 4 ms
4,352 KB
testcase_18 AC 5 ms
4,352 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 4 ms
4,352 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 4 ms
4,352 KB
testcase_25 AC 3 ms
4,352 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 4 ms
4,352 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 5 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:59:21: 警告: ‘ans1’ may be used uninitialized [-Wmaybe-uninitialized]
   59 |     cout << vec[ans1] << endl;
      |                     ^
main.cpp:36:18: 備考: ‘ans1’ はここで定義されています
   36 |     int ans = 0, ans1;
      |                  ^~~~

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
bool b[200020] = { false };
vector<int> vec;
int main() {
    int l, r;
    cin >> l >> r;
    b[1] = true;
    for (int i = 2; i <= 200000; i++) {
        if (!b[i]) {
            for (int j = i + i; j <= 200000; j += i) {
                b[j] = true;
            }
        }
    }
    for (int i = l; i <= r; i++) {
        if (!b[i]) {
            vec.emplace_back(i);
        }
    }
    int n = vec.size();
    int ans = 0, ans1;
    set<int> st;
    int right = 0;
    for (int left = 0; left < n; left++) {
        while (right < n) {
            auto itr = st.find(vec[right] % 9);
            if (itr != st.end() && st.size() != 0) {
                break;
            }
            st.insert(vec[right] % 9);
            right++;
        }
        if (ans <= right - left - 1) {
            ans = right - left - 1;
            ans1 = left;
        }
        if (right == left) {
            right++;
        }
        else {
            st.erase(vec[left] % 9);
        }
    }
    cout << vec[ans1] << endl;
}
0