結果
| 問題 | No.2593 Reorder and Mod 120 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-21 18:17:00 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,075 bytes |
| 記録 | |
| コンパイル時間 | 339 ms |
| コンパイル使用メモリ | 41,088 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-07-03 07:25:14 |
| 合計ジャッジ時間 | 1,459 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include <cstdio>
// mod 3: constant
// mod 5: determined only by the lowest one digit
// mod 8: determined only by the lowest three digits
int main() {
int n;
std::scanf("%d", &n);
char s[200000]{};
std::scanf("%s", s);
int cnt[10]{}, flg[40]{};
for (int i = 0; i < n; ++i) ++cnt[s[i] - '0'];
for (int x = 1; x <= 9; ++x) {
--cnt[x];
for (int y = 1; y <= 9; ++y) {
if (n <= 1) y = 0;
else --cnt[y];
for (int z = 1; z <= 9; ++z) {
if (n <= 2) z = 0;
else --cnt[z];
if (cnt[x] >= 0 and cnt[y] >= 0 and cnt[z] >= 0) {
int mod8 = (100 * z + 10 * y + x) % 8;
int mod5 = x % 5;
flg[mod8 * 5 + mod5] = 1;
}
if (n <= 2) break;
else ++cnt[z];
}
if (n <= 1) break;
else ++cnt[y];
}
++cnt[x];
}
int ans = 0;
for (int v = 0; v < 40; ++v) ans += flg[v];
std::printf("%d\n", ans);
}