結果

問題 No.2207 pCr検査
ユーザー Ricky_ponRicky_pon
提出日時 2023-02-04 18:58:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,562 bytes
コンパイル時間 1,474 ms
コンパイル使用メモリ 140,396 KB
実行使用メモリ 87,000 KB
最終ジャッジ日時 2023-09-16 15:30:03
合計ジャッジ時間 79,420 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 TLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2,904 ms
70,604 KB
testcase_13 AC 1,585 ms
43,720 KB
testcase_14 AC 363 ms
14,384 KB
testcase_15 TLE -
testcase_16 AC 1,470 ms
39,540 KB
testcase_17 AC 2,712 ms
65,232 KB
testcase_18 AC 2,054 ms
52,608 KB
testcase_19 AC 952 ms
27,620 KB
testcase_20 AC 1,615 ms
41,308 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 511 ms
18,416 KB
testcase_25 AC 1,407 ms
36,880 KB
testcase_26 AC 1,298 ms
35,748 KB
testcase_27 AC 2,755 ms
65,920 KB
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:201:19: 警告: ‘n’ may be used uninitialized [-Wmaybe-uninitialized]
  201 |             printf("%d %d\n", n, r + 1);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:174:9: 備考: ‘n’ はここで定義されています
  174 |     int n;
      |         ^

ソースコード

diff #

// #include <bits/stdc++.h>
#include <string.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second


#include <algorithm>
#include <bitset>
#include <vector>

namespace rklib {

struct SimpleSieve {
    std::vector<bool> is_prime;
    std::vector<int> prime;

    SimpleSieve(int n) {
        is_prime.resize(n + 1, true);
        is_prime[0] = is_prime[1] = false;
        for (int i = 2; i <= n; ++i) {
            if (!is_prime[i]) continue;
            prime.push_back(i);
            for (int j = 2; i * j <= n; ++j) {
                is_prime[i * j] = false;
            }
        }
    }
};

struct Sieve {
    std::vector<int> min_factor, prime;

    Sieve(int n) {
        min_factor.resize(n + 1, 0);
        for (int i = 2; i <= n; ++i) {
            if (min_factor[i] == 0) {
                min_factor[i] = i;
                prime.push_back(i);
            }
            for (int x : prime) {
                if (x * i > n || x > i) break;
                min_factor[x * i] = x;
            }
        }
    }

    std::vector<std::pair<int, int>> prime_factor(int n) {
        std::vector<std::pair<int, int>> res;
        while (n > 1) {
            if (res.empty() || res.rbegin()->first != min_factor[n]) {
                res.emplace_back(min_factor[n], 1);
            } else
                ++res.rbegin()->second;
            n /= min_factor[n];
        }
        return res;
    }

    void divisor_dfs(std::vector<std::pair<int, int>> &p, int t, int cur,
                     std::vector<int> &res) {
        if (cur == (int)p.size()) {
            res.push_back(t);
            return;
        }
        divisor_dfs(p, t, cur + 1, res);
        for (int _ = 0; _ < p[cur].second; ++_) {
            t *= p[cur].first;
            divisor_dfs(p, t, cur + 1, res);
        }
    }

    std::vector<int> get_divisor(int n, bool sorted = false) {
        std::vector<int> res;
        auto p = prime_factor(n);
        divisor_dfs(p, 1, 0, res);
        if (sorted) sort(res.begin(), res.end());
        return res;
    }
};

}  // namespace rklib


#include <algorithm>
#include <cassert>
#include <vector>

namespace rklib {

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool chmin_non_negative(T &a, const T &b) {
    if (a < 0 || a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}

template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

}  // namespace rklib


using namespace std;
using namespace rklib;

using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;

int prime_factors[10'000'010];

int main() {
    int K;
    scanf("%d", &K);
    int n;
    rep(i, K) {
        int p, e;
        scanf("%d%d", &p, &e);
        prime_factors[p] += e;
        if (i == K - 1) n = p;
    }

    Sieve sv(n);
    int cnt_nonzero = count_if(prime_factors, prime_factors + n + 1,
                               [](const int x) { return x != 0; });
    rep(r, n) {
        {
            auto ps = sv.prime_factor(r + 1);
            for (auto [t, e] : ps) {
                if (prime_factors[t] == 0) ++cnt_nonzero;
                prime_factors[t] += e;
            }
        }
        {
            auto ps = sv.prime_factor(n - r);
            for (auto [t, e] : ps) {
                prime_factors[t] -= e;
                if (prime_factors[t] == 0) --cnt_nonzero;
            }
        }
        if (cnt_nonzero == 0) {
            printf("%d %d\n", n, r + 1);
            return 0;
        }
    }
    printf("%d %d\n", -1, -1);
}
0