結果

問題 No.1106 🦉 何事もバランスが大事
ユーザー chocorusk
提出日時 2020-07-03 22:18:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 3,010 ms
コンパイル使用メモリ 131,980 KB
最終ジャッジ日時 2025-01-11 14:46:56
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 77
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
map<pair<P, int>, ll> dp;
ll solve(ll l, ll r, int d){
	if(r<=6){
		ll ans=0;
		int a[7]={0, 1, 2, -1, 0, 1, 2};
		for(int i=l; i<=r; i++) if(a[i]==d) ans++;
		return ans;
	}
	if(dp.find({{l, r}, d})!=dp.end()){
		return dp[{{l, r}, d}];
	}
	ll ans=0;
	for(int i=-2; i<3; i++){
		ans+=solve((l-i+4)/5, (r-i)/5, d-i);
	}
	return dp[{{l, r}, d}]=ans;
}
int main()
{
	ll n; cin>>n;
	cout<<solve(1, n, 0)<<endl;
	return 0;
}
0