結果
問題 | No.732 3PrimeCounting |
ユーザー | mai |
提出日時 | 2018-09-07 22:59:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,206 bytes |
コンパイル時間 | 2,284 ms |
コンパイル使用メモリ | 214,036 KB |
実行使用メモリ | 14,764 KB |
最終ジャッジ日時 | 2024-05-07 05:13:50 |
合計ジャッジ時間 | 35,276 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 342 ms
14,760 KB |
testcase_01 | AC | 342 ms
9,384 KB |
testcase_02 | AC | 341 ms
9,388 KB |
testcase_03 | AC | 345 ms
9,388 KB |
testcase_04 | AC | 342 ms
9,388 KB |
testcase_05 | AC | 343 ms
9,388 KB |
testcase_06 | AC | 344 ms
9,364 KB |
testcase_07 | AC | 351 ms
9,388 KB |
testcase_08 | AC | 345 ms
9,388 KB |
testcase_09 | AC | 349 ms
9,388 KB |
testcase_10 | AC | 346 ms
9,392 KB |
testcase_11 | AC | 344 ms
9,516 KB |
testcase_12 | AC | 349 ms
9,392 KB |
testcase_13 | AC | 348 ms
9,388 KB |
testcase_14 | AC | 348 ms
9,388 KB |
testcase_15 | AC | 352 ms
9,388 KB |
testcase_16 | AC | 351 ms
9,512 KB |
testcase_17 | AC | 359 ms
9,392 KB |
testcase_18 | AC | 349 ms
9,384 KB |
testcase_19 | AC | 348 ms
9,512 KB |
testcase_20 | AC | 421 ms
9,388 KB |
testcase_21 | AC | 590 ms
9,344 KB |
testcase_22 | AC | 585 ms
9,384 KB |
testcase_23 | AC | 372 ms
9,384 KB |
testcase_24 | AC | 377 ms
9,388 KB |
testcase_25 | AC | 783 ms
9,388 KB |
testcase_26 | AC | 667 ms
9,388 KB |
testcase_27 | AC | 449 ms
9,348 KB |
testcase_28 | AC | 445 ms
9,384 KB |
testcase_29 | AC | 539 ms
9,512 KB |
testcase_30 | AC | 565 ms
9,424 KB |
testcase_31 | AC | 609 ms
9,388 KB |
testcase_32 | AC | 699 ms
9,388 KB |
testcase_33 | AC | 710 ms
9,388 KB |
testcase_34 | AC | 707 ms
9,388 KB |
testcase_35 | AC | 636 ms
9,512 KB |
testcase_36 | AC | 640 ms
9,388 KB |
testcase_37 | AC | 400 ms
9,392 KB |
testcase_38 | AC | 397 ms
9,388 KB |
testcase_39 | AC | 652 ms
9,384 KB |
testcase_40 | AC | 620 ms
9,392 KB |
testcase_41 | AC | 622 ms
9,384 KB |
testcase_42 | AC | 628 ms
9,392 KB |
testcase_43 | AC | 559 ms
9,380 KB |
testcase_44 | AC | 566 ms
9,384 KB |
testcase_45 | AC | 480 ms
9,384 KB |
testcase_46 | AC | 467 ms
9,392 KB |
testcase_47 | AC | 495 ms
9,388 KB |
testcase_48 | AC | 814 ms
9,380 KB |
testcase_49 | AC | 813 ms
9,388 KB |
testcase_50 | AC | 592 ms
9,512 KB |
testcase_51 | AC | 589 ms
9,512 KB |
testcase_52 | AC | 468 ms
9,392 KB |
testcase_53 | AC | 1,212 ms
9,384 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 | -- | - |
ソースコード
#pragma GCC optimize ("O3") #include "bits/stdc++.h" using namespace std; using ll = long long int; #define debugos cout #define debug(v) {printf("L%d %s > ",__LINE__,#v);debugos<<(v)<<endl;} #define debugv(v) {printf("L%d %s > ",__LINE__,#v);for(auto e:(v)){debugos<<e<<" ";}debugos<<endl;} #define debuga(m,w) {printf("L%d %s > ",__LINE__,#m);for(int x=0;x<(w);x++){debugos<<(m)[x]<<" ";}debugos<<endl;} #define debugaa(m,h,w) {printf("L%d %s >\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){debugos<<(m)[y][x]<<" ";}debugos<<endl;}} #define ALL(v) (v).begin(),(v).end() #define repeat(cnt,l) for(remove_reference<remove_const<decltype(l)>::type>::type cnt=0;(cnt)<(l);++(cnt)) #define rrepeat(cnt,l) for(auto cnt=(l)-1;0<=(cnt);--(cnt)) #define iterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);++(cnt)) #define diterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);--(cnt)) const ll MD = 1000000007ll; const long double PI = 3.1415926535897932384626433832795L; inline void assert_call(bool assertion, function<void()> f) { if (!assertion) { cerr << "assertion fault:" << endl; f(); abort(); } } template<typename T1, typename T2> inline ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << '(' << p.first << ':' << p.second << ')'; return o; } template<typename Vec> inline ostream& _ostream_vecprint(ostream& os, const Vec& a) { os << '['; for (const auto& e : a) os << ' ' << e << ' '; os << ']'; return os; } template<typename T> inline ostream& operator<<(ostream& o, const vector<T>& v) { return _ostream_vecprint(o, v); } template<typename T, size_t S> inline ostream& operator<<(ostream& o, const array<T, S>& v) { return _ostream_vecprint(o, v); } template<typename T> inline T& maxset(T& to, const T& val) { return to = max(to, val); } template<typename T> inline T& minset(T& to, const T& val) { return to = min(to, val); } void bye(string s, int code = 0) { cout << s << endl; exit(code); } mt19937_64 randdev(8901016); template<typename T> inline T rand(T l, T h) { return uniform_int_distribution<T>(l, h)(randdev); } template<> inline double rand<double>(double l, double h) { return uniform_real_distribution<double>(l, h)(randdev); } template<> inline float rand<float>(float l, float h) { return uniform_real_distribution<float>(l, h)(randdev); } template<int Max = 2000> class IsPrimeC { bool d_[Max + 1]; template<typename T> static T cesqrt(T s) { double x = s / 2.0; double prev = 0.0; while (x != prev) { prev = x; x = (x + s / x) / 2.0; } return x; } public: IsPrimeC() : d_() { d_[0] = d_[1] = 1; int sqh = cesqrt<int>(Max); for (int i = 2; i <= sqh; i++) { if (d_[i] == 0) { for (int j = i * i; j <= Max; j += i) { // i*i d_[j] = 1; } } } for (int i = 0; i <= Max; ++i) d_[i] = !d_[i]; } inline bool operator[](int x) const { return d_[x]; } }; template<int Max = 2000> class PrimeList { int d_[Max]; public: PrimeList() : d_() { int n = 1; d_[0] = 2; for (int x = 3; n < Max; ++x) { bool f = true; for (int i = 0; d_[i] * d_[i] <= x; ++i) if (x % d_[i] == 0) { f = false; break; } if (f) d_[n++] = x; } } inline int operator[](int x) const { return d_[x]; } template<int Max_> class iterator { const PrimeList<Max_>& pl; int ptr = 0; public: iterator(const decltype(pl)& _pl, int _ptr = 0) :pl(_pl), ptr(_ptr) { } int operator*() const { return pl[ptr]; } iterator<Max_>& operator++() { ptr++; return *this; } // prefix inline bool operator!=(const iterator<Max_>& it) const { return ptr != it.ptr ? !(Max < ptr && Max < it.ptr) : false; } inline bool operator==(const iterator<Max_>& it) const { return ptr != it.ptr ? (Max < ptr && Max < it.ptr) : true; } }; PrimeList::iterator<Max> begin() const { return PrimeList::iterator<Max>(*this, 0); } PrimeList::iterator<Max> end() const { return PrimeList::iterator<Max>(*this, Max); } }; IsPrimeC<300001> isPrime; PrimeList<300001> primeList; ll N; int main() { cin >> N; vector<ll> dp; dp.resize(300001); int last = 0; for (last = 0; primeList[last] <= N; ++last) { dp[primeList[last]] = 1; } repeat(_, 2) { vector<ll> dp2(300001); rrepeat(i, last) { int p = primeList[i]; repeat(j, 300001) { if (!j) continue; if (j + p > 3 * N) continue; dp2[j + p] += dp[j]; } } dp.swap(dp2); } ll ans = 0; for (ll p : primeList) { if (p >= dp.size()) break; ans += dp[p]; } for (int i = 0; primeList[i] <= N; ++i) { int vi = primeList[i]; for (int j = i + 1; primeList[j] <= N; ++j) { if (vi * 2 + primeList[j] >= dp.size()) break; ans -= isPrime[vi * 2 + primeList[j]] * 3; ans -= isPrime[vi + primeList[j]*2] * 3; } } cout << ans/6 << endl; return 0; }