結果

問題 No.2187 三立法和 mod 333
ユーザー otamay6otamay6
提出日時 2023-01-14 16:32:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,542 bytes
コンパイル時間 2,474 ms
コンパイル使用メモリ 200,408 KB
実行使用メモリ 15,288 KB
最終ジャッジ日時 2023-08-26 22:23:45
合計ジャッジ時間 9,148 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 61 ms
14,980 KB
testcase_03 AC 29 ms
14,980 KB
testcase_04 AC 29 ms
15,028 KB
testcase_05 AC 67 ms
15,040 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 67 ms
15,148 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 30 ms
15,144 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 29 ms
15,040 KB
testcase_24 TLE -
testcase_25 AC 29 ms
14,980 KB
testcase_26 AC 29 ms
15,148 KB
testcase_27 TLE -
testcase_28 AC 66 ms
15,052 KB
testcase_29 TLE -
testcase_30 AC 61 ms
15,088 KB
testcase_31 AC 64 ms
15,116 KB
testcase_32 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

std::pair<ll,ll> bisearch(ll l,ll r,std::function<bool(ll)> f){
    while((l+1)<r){
        ll m=(l+r)/2;
        if(f(m)) r=m;
        else l=m;
    }
    return std::make_pair(l,r);
}

constexpr int mod = 333;
ll cnt[4445][mod]; // iまでにz^3がj mod 333であるような数
ll p4[4445];
ll p3[4445];
ll p3m[4445];

int main(){
    int a;cin>>a;
    for(ll z = 1; z <= 4444; z++)
    {
        ll z3 = z*z*z;
        REP(i, mod) cnt[z][i] = cnt[z-1][i];
        cnt[z][z3%mod]++;
        p3[z] = z3;
        p3m[z] = p3[z] % mod;
        p4[z] = z3*z;
    }
    int ans = 0;
    #if 1
    for(int x = 1; x < 4444; x++)
    {
        int ans2 = 0;
        for(int y = x; y < 4444; y++)
        {
            int z3 = (a + 2 * mod - (p3m[x] + p3m[y]))%mod;
            if(cnt[4444][z3] <= 0) continue;
            ll zmax = p4[4444] - p4[x] - p4[y];
            if(zmax <= 0) break;
            zmax = bisearch(0, 4444, [&](int idx){return p4[idx] > zmax;}).first;
            int c = cnt[zmax][z3];
            //if(c > 0 && cnt[4444][z3] == 0) cerr << x << " " << y << " " << zmax << " " << z3 << " " << c << endl;
            if(y==x) ans += c;
            else ans2 += c;
        }
        ans += 2 * ans2;
        //cerr << x << "\n";
    }
    #endif
    cout << ans << endl;
}
0