結果

問題 No.732 3PrimeCounting
ユーザー keikei
提出日時 2018-09-07 22:05:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,178 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 168,292 KB
実行使用メモリ 11,324 KB
最終ジャッジ日時 2023-08-19 18:57:51
合計ジャッジ時間 44,858 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,600 KB
testcase_01 AC 4 ms
4,384 KB
testcase_02 AC 5 ms
4,524 KB
testcase_03 AC 5 ms
4,508 KB
testcase_04 AC 5 ms
4,568 KB
testcase_05 AC 5 ms
4,612 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 4 ms
4,524 KB
testcase_10 AC 5 ms
4,528 KB
testcase_11 AC 4 ms
4,384 KB
testcase_12 AC 5 ms
4,448 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,568 KB
testcase_15 AC 5 ms
4,392 KB
testcase_16 AC 4 ms
4,580 KB
testcase_17 AC 5 ms
4,564 KB
testcase_18 AC 4 ms
4,516 KB
testcase_19 AC 5 ms
4,512 KB
testcase_20 AC 5 ms
4,656 KB
testcase_21 AC 8 ms
4,576 KB
testcase_22 AC 8 ms
4,432 KB
testcase_23 AC 5 ms
4,400 KB
testcase_24 AC 5 ms
4,504 KB
testcase_25 AC 17 ms
4,724 KB
testcase_26 AC 11 ms
4,400 KB
testcase_27 AC 6 ms
4,392 KB
testcase_28 AC 5 ms
4,448 KB
testcase_29 AC 7 ms
4,568 KB
testcase_30 AC 7 ms
4,512 KB
testcase_31 AC 9 ms
4,508 KB
testcase_32 AC 13 ms
4,564 KB
testcase_33 AC 13 ms
4,612 KB
testcase_34 AC 14 ms
4,376 KB
testcase_35 AC 9 ms
4,436 KB
testcase_36 AC 9 ms
4,516 KB
testcase_37 AC 5 ms
4,388 KB
testcase_38 AC 5 ms
4,580 KB
testcase_39 AC 10 ms
4,452 KB
testcase_40 AC 10 ms
4,648 KB
testcase_41 AC 9 ms
4,624 KB
testcase_42 AC 9 ms
4,604 KB
testcase_43 AC 8 ms
4,564 KB
testcase_44 AC 7 ms
4,524 KB
testcase_45 AC 6 ms
4,432 KB
testcase_46 AC 6 ms
4,512 KB
testcase_47 AC 6 ms
4,508 KB
testcase_48 AC 20 ms
4,608 KB
testcase_49 AC 19 ms
4,668 KB
testcase_50 AC 9 ms
4,432 KB
testcase_51 AC 9 ms
4,584 KB
testcase_52 AC 5 ms
4,624 KB
testcase_53 AC 61 ms
4,800 KB
testcase_54 AC 1,388 ms
5,636 KB
testcase_55 AC 1,388 ms
5,780 KB
testcase_56 AC 1,396 ms
5,720 KB
testcase_57 AC 220 ms
4,844 KB
testcase_58 AC 220 ms
5,024 KB
testcase_59 AC 68 ms
4,796 KB
testcase_60 AC 352 ms
5,064 KB
testcase_61 AC 354 ms
4,968 KB
testcase_62 AC 1,876 ms
6,068 KB
testcase_63 AC 727 ms
5,400 KB
testcase_64 AC 474 ms
5,304 KB
testcase_65 AC 474 ms
5,324 KB
testcase_66 AC 5 ms
4,376 KB
testcase_67 AC 5 ms
4,580 KB
testcase_68 AC 1,601 ms
5,908 KB
testcase_69 AC 1,606 ms
5,764 KB
testcase_70 AC 1,414 ms
5,852 KB
testcase_71 AC 1,416 ms
5,852 KB
testcase_72 AC 673 ms
5,432 KB
testcase_73 TLE -
testcase_74 TLE -
testcase_75 AC 16 ms
4,728 KB
testcase_76 AC 1,558 ms
5,748 KB
testcase_77 AC 243 ms
4,972 KB
testcase_78 AC 2,393 ms
6,308 KB
testcase_79 AC 1,630 ms
5,760 KB
testcase_80 AC 2,109 ms
6,008 KB
testcase_81 AC 1,434 ms
5,748 KB
testcase_82 AC 6 ms
4,388 KB
testcase_83 AC 231 ms
5,152 KB
testcase_84 AC 266 ms
4,968 KB
testcase_85 AC 1,176 ms
5,796 KB
testcase_86 AC 2,165 ms
6,056 KB
testcase_87 TLE -
testcase_88 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MAX_PRIME = 300050;
vector<int> primes;
vector<int> is_prime(MAX_PRIME + 1,true);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false;
        }
    }
}

int dp[4][MAX_PRIME];
ll solve(){
    init_primes();
    ll res = 0;
    ll N; cin >> N;
    dp[0][0] = 1;
    for(int i = 0; i < primes.size();i++){
        if(N < primes[i]) continue;
        for(int j = 2; j >= 0;j--){
            for(int k = 3*primes[i]; k >= 0;k--){
                if(dp[j][k] == 0) continue;
                dp[j+1][k+primes[i]] += dp[j][k];
            }
        }
    }
    for(int i = 0; i <= 3*N;i++){
        if(is_prime[i]){
            res += dp[3][i];
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}
0