結果

問題 No.732 3PrimeCounting
ユーザー keikei
提出日時 2018-09-07 22:01:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,227 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 168,224 KB
実行使用メモリ 4,932 KB
最終ジャッジ日時 2023-08-19 18:45:46
合計ジャッジ時間 21,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,660 KB
testcase_01 AC 8 ms
4,520 KB
testcase_02 AC 10 ms
4,600 KB
testcase_03 AC 10 ms
4,496 KB
testcase_04 AC 10 ms
4,636 KB
testcase_05 AC 10 ms
4,664 KB
testcase_06 AC 11 ms
4,752 KB
testcase_07 AC 11 ms
4,816 KB
testcase_08 AC 12 ms
4,652 KB
testcase_09 AC 11 ms
4,540 KB
testcase_10 AC 12 ms
4,536 KB
testcase_11 AC 12 ms
4,640 KB
testcase_12 AC 13 ms
4,504 KB
testcase_13 AC 13 ms
4,492 KB
testcase_14 AC 14 ms
4,652 KB
testcase_15 AC 14 ms
4,644 KB
testcase_16 AC 14 ms
4,552 KB
testcase_17 AC 14 ms
4,560 KB
testcase_18 AC 15 ms
4,648 KB
testcase_19 AC 15 ms
4,804 KB
testcase_20 AC 115 ms
4,656 KB
testcase_21 AC 365 ms
4,652 KB
testcase_22 AC 365 ms
4,616 KB
testcase_23 AC 47 ms
4,648 KB
testcase_24 AC 48 ms
4,552 KB
testcase_25 AC 645 ms
4,672 KB
testcase_26 AC 479 ms
4,724 KB
testcase_27 AC 158 ms
4,520 KB
testcase_28 AC 159 ms
4,764 KB
testcase_29 AC 298 ms
4,580 KB
testcase_30 AC 299 ms
4,672 KB
testcase_31 AC 392 ms
4,596 KB
testcase_32 AC 535 ms
4,516 KB
testcase_33 AC 540 ms
4,840 KB
testcase_34 AC 544 ms
4,684 KB
testcase_35 AC 431 ms
4,600 KB
testcase_36 AC 432 ms
4,676 KB
testcase_37 AC 83 ms
4,620 KB
testcase_38 AC 83 ms
4,556 KB
testcase_39 AC 447 ms
4,536 KB
testcase_40 AC 407 ms
4,512 KB
testcase_41 AC 408 ms
4,648 KB
testcase_42 AC 408 ms
4,656 KB
testcase_43 AC 331 ms
4,668 KB
testcase_44 AC 331 ms
4,724 KB
testcase_45 AC 191 ms
4,560 KB
testcase_46 AC 190 ms
4,600 KB
testcase_47 AC 238 ms
4,572 KB
testcase_48 AC 688 ms
4,668 KB
testcase_49 AC 689 ms
4,676 KB
testcase_50 AC 369 ms
4,660 KB
testcase_51 AC 375 ms
4,684 KB
testcase_52 AC 178 ms
4,668 KB
testcase_53 AC 1,276 ms
4,932 KB
testcase_54 TLE -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
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;
        }
    }
}

ll 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 = MAX_PRIME; 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]){
         //   cout << i << " " << dp[3][i] << endl;
            res += dp[3][i];
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}
0