結果
問題 | No.1106 🦉 何事もバランスが大事 |
ユーザー |
|
提出日時 | 2020-07-04 14:40:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 2,189 bytes |
コンパイル時間 | 2,027 ms |
コンパイル使用メモリ | 170,296 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 01:30:39 |
合計ジャッジ時間 | 3,697 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 77 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} ll nextLong() { ll x; scanf("%lld", &x); return x;} vector<int> f(ll N) { vector<int> v; while (N != 0) { int r = (N % 5); if (r == 4) { v.push_back(-1); N += 4; } if (r == 3) { v.push_back(-2); N += 3; } if (r == 2) { v.push_back(2); N -= 2; } if (r == 1) { v.push_back(1); N -= 1; } if (r == 0) { v.push_back(0); } N /= 5; } reverse(ALL(v)); return v; } ll dp[30][2][2][200]; int main2() { CLR(dp, 0); ll N = nextLong(); auto v = f(N); // cout << "N=" << N << " : "; // pv(ALL(v)); reverse(ALL(v)); const int O = 100; const int n = v.size(); dp[n][0][0][O] = 1; for (int i = n-1; i >= 0; i--) { REP(isSmaller, 2) { REP(isPositive, 2) { for (int balance = -2*n; balance <= 2*n; balance++) { ll base = dp[i+1][isSmaller][isPositive][balance+O]; for (int x = -2; x <= 2; x++) { if (!isPositive && x < 0) continue; if (!isSmaller && x > v[i]) continue; int n_isSmaller = isSmaller || (v[i] > x); int n_isPositive = isPositive || (x > 0); int n_balance = balance + x; dp[i][n_isSmaller][n_isPositive][n_balance+O] += base; } } } } } ll ans = dp[0][0][1][O] + dp[0][1][1][O]; cout << ans << endl; return 0; } int main() { // for (int n = 1; n <= 20; n++) { // vector<int> v = f(n); // cout << "n=" << n << ": "; // pv(ALL(v)); // } // { // auto v = f(1e18); // pv(ALL(v)); // int n = v.size(); // cout << (ll)pow(5, n) << endl; // } // return 0; #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }