結果
問題 | No.2593 Reorder and Mod 120 |
ユーザー |
|
提出日時 | 2023-12-21 09:24:41 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 750 bytes |
コンパイル時間 | 1,359 ms |
コンパイル使用メモリ | 136,628 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-27 10:51:23 |
合計ジャッジ時間 | 2,100 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 26 |
ソースコード
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; void main(){ auto N = readln.chomp.to!long; auto S = readln.chomp; if(N == 1){ writeln(1); return; } if(N == 2){ writeln(S[0] == S[1] ? 1 : 2); return; } auto count = new ulong[10]; ulong mod = 0; foreach(c; S){ count[c - '0']++; mod += c - '0'; } mod %= 3; bool[long] result; for(auto i = 0; i < 1000; i++){ auto s = "%03d".format(i); auto cnt = new ulong[10]; auto m = 0; foreach(c; s){ cnt[c - '0']++; m += c - '0'; } m %= 3; if(iota(10).any!(a => cnt[a] > count[a])) continue; result[((mod + 3 - m) * 1000 + i) % 120] = true; } result.length.writeln; }