結果
| 問題 |
No.220 世界のなんとか2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-30 19:10:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 3,018 bytes |
| コンパイル時間 | 884 ms |
| コンパイル使用メモリ | 76,932 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 00:59:51 |
| 合計ジャッジ時間 | 1,594 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
struct nantoka_of_world{
string N;
long dp[100][2][2][3];
long find(int now, bool is_less, bool is_in_3, int mod_3){
if(dp[now][is_less][is_in_3][mod_3] != -1){
return dp[now][is_less][is_in_3][mod_3];
}else if(now == N.size()){
return dp[now][is_less][is_in_3][mod_3] = is_in_3 || !mod_3;
}else{
long ans = 0;
for(int i = 0; i <= N[now] - '0' || (is_less && i < 10); i++){
ans += find(now + 1, is_less || (i < N[now] - '0'), is_in_3 || (i == 3), (mod_3 + i) % 3);
}
return dp[now][is_less][is_in_3][mod_3] = ans;
}
}
long calculate(long num){
N = to_string(num);
memset(dp, -1, sizeof(dp));
return find(0, false, false, 0);
}
long calculate(string num){
N = num;
memset(dp, -1, sizeof(dp));
return find(0, false, false, 0);
}
} table;
int main(){
int P;
cin >> P;
string N = "1" + string(P, '0');
cout << table.calculate(N) - 1 << endl;
}