結果
問題 |
No.1185 完全な3の倍数
|
ユーザー |
![]() |
提出日時 | 2020-08-22 14:41:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 318 ms / 2,000 ms |
コード長 | 913 bytes |
コンパイル時間 | 5,478 ms |
コンパイル使用メモリ | 194,692 KB |
最終ジャッジ日時 | 2025-01-13 08:50:09 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair<int,int> P; int main() { int m; cin >> m; string s; s = to_string(m); int n = s.size(); int res = 0; string cur = ""; auto dfs = [&](auto& f, int len)->void{ if (len > n) return ; int t = 0; int ok = 1; for (int i = 0; i < len; i++) { int a = cur[i] - '0'; t = t * 10 + a; for (int j = i + 1; j < len; j++) { int b = cur[j] - '0'; if ((a + b) % 3 != 0) ok = 0; } } if (len > 1) ok &= (t % 3 == 0); if (t <= m && len > 1) { res += ok; } if (!ok) return ; for (int d = (len ? 0 : 1); d <= 9; d++) { cur += char(d + '0'); f(f, len + 1); cur.pop_back(); } }; dfs(dfs, 0); cout << res << endl; return 0; }