結果
問題 | No.220 世界のなんとか2 |
ユーザー | jupiro |
提出日時 | 2020-07-10 20:45:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,730 bytes |
コンパイル時間 | 1,394 ms |
コンパイル使用メモリ | 134,728 KB |
最終ジャッジ日時 | 2025-01-11 17:32:39 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n; cin >> n; string s; s += '1'; for (int i = 0; i < n; i++) s += '0'; vector dp(s.size() + 1, vector(2, vector(2, vector<ll>(3)))); dp[0][0][0][0] = 1; for (int i = 0; i < s.size(); i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) for (int l = 0; l < 3; l++) for (int m = 0; m < 10; m++) { if (!j and m > s[i] - '0') continue; int nj = j | (m != (s[i] - '0')); int nk = k | (m == 3); int nl = (l + m) % 3; dp[i + 1][nj][nk][nl] += dp[i][j][k][l]; } ll res = 0; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) { if (j == 1 or k == 0) res += dp[s.size()][i][j][k]; } cout << res - 1 << endl; return 0; }