結果
| 問題 |
No.1106 🦉 何事もバランスが大事
|
| コンテスト | |
| ユーザー |
snow39
|
| 提出日時 | 2020-07-04 00:23:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,196 bytes |
| コンパイル時間 | 807 ms |
| コンパイル使用メモリ | 94,952 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 05:16:28 |
| 合計ジャッジ時間 | 2,697 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 77 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
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 dp[32][128][2][2];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin>>N;
vector<int> A(31,0);
{
ll M=N;
for(int i=0;i<=30;i++){
A[i]=N%5;
N/=5;
}
}
dp[30][60][0][0]=1;
for(int i=29;i>=0;i--) for(int j=0;j<=120;j++) rep(k,2) rep(l,2){
ll val=dp[i+1][j][k][l];
if(val==0) continue;
for(int d=0;d<5;d++) for(int nk=0;nk<2;nk++){
int nl=l|(d<A[i]);
if(l==0&&d>A[i]) continue;
int need=k*5-nk-d;
if(need<-2||2<need) continue;
int nj=j+need;
dp[i][nj][nk][nl]+=val;
}
}
ll ans=dp[0][60][0][0]+dp[0][60][0][1]-1;
cout<<ans<<endl;
return 0;
}
snow39