結果
| 問題 |
No.1106 🦉 何事もバランスが大事
|
| コンテスト | |
| ユーザー |
IKyopro
|
| 提出日時 | 2020-07-04 00:24:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 1,343 bytes |
| コンパイル時間 | 1,953 ms |
| コンパイル使用メモリ | 194,964 KB |
| 最終ジャッジ日時 | 2025-01-11 15:15:05 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 77 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
ll dp[40][100][100][2][2] = {};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
ll five = 1;
while(5*five<=N) five *= 5;
string S = "";
ll n = N;
while(five){
ll a = n/five;
S += (char) '0'+a;
n -= five*a;
five /= 5;
}
cerr << S << "\n";
int M = S.size();
int A = 60;
dp[0][0][0][0][0] = 1;
dp[0][1][0][0][1] = 1;
for(int i=0;i<M;i++) for(int l=0;l<A;l++) for(int r=0;r<A;r++) for(int k=0;k<2;k++) for(int j=0;j<2;j++){
int x = S[i]-'0';
for(int n=0;n<5;n++){
int nk = (k || n<x);
if(!k && n>x) continue;
for(int a=0;a<3;a++) for(int b=0;b<3;b++){
if(a+b>2) continue;
if(a==b && a>0) continue;
int nl = l+a,nr = r+b;
int nj = 0;
if(a+5*j-b==n) nj = 0;
else if(a+5*j-b==n+1) nj = 1;
else continue;
dp[i+1][nl][nr][nk][nj] += dp[i][l][r][k][j];
}
}
}
ll ans = 0;
for(int i=0;i<A;i++) ans += dp[M][i][i][0][0]+dp[M][i][i][1][0];
cout << ans-1 << "\n";
}
IKyopro