結果
| 問題 |
No.1185 完全な3の倍数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-22 16:36:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,706 bytes |
| コンパイル時間 | 1,595 ms |
| コンパイル使用メモリ | 167,660 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-21 09:19:30 |
| 合計ジャッジ時間 | 2,967 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 22 |
ソースコード
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
ll count3(int a, bool j) {
int res = 0;
if (j) {
for (int i = 0; i <= a; i++) {
if (i % 3 == 0)
res++;
}
} else {
for (int i = 1; i <= a; i++) {
if (i % 3 == 0)
res++;
}
}
return res;
}
ll cnt(int size) {
ll res = 0;
for (int i = 2; i < size - 1; i++) {
res += 3 * pow(4, i);
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int ans = 0;
if (N < 300) {
for (int i = 10; i <= N; i++) {
if (i % 3 != 0)
continue;
string s = to_string(i);
bool judge = 1;
rep(j, s.size()) {
for (int k = j + 1; k < s.size(); k++) {
if (((s[j] - '0') + (s[k] - '0')) % 3 != 0) {
judge = 0;
break;
}
}
}
if (judge) {
ans++;
}
}
} else {
ans = 30;
ll res = 1;
string s = to_string(N);
rep(i, s.size()) {
if (i == 0) {
res *= count3(s[i] - '0', 0);
} else {
res *= count3(s[i] - '0', 1);
}
}
ans += res;
ans += cnt(s.size());
}
cout << ans << endl;
}