結果
| 問題 |
No.2593 Reorder and Mod 120
|
| コンテスト | |
| ユーザー |
ldsyb
|
| 提出日時 | 2023-12-24 20:07:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,392 bytes |
| コンパイル時間 | 3,954 ms |
| コンパイル使用メモリ | 257,716 KB |
| 最終ジャッジ日時 | 2025-02-18 14:17:22 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
int main()
{
int64_t n;
string s;
cin >> n >> s;
if (n < 3)
{
set<int64_t> st;
sort(s.begin(), s.end());
do
{
int64_t x = 0;
for (auto &&c : s)
{
x *= 10;
x += c - '0';
}
st.insert(x % 120);
} while (next_permutation(s.begin(), s.end()));
cout << st.size() << endl;
return 0;
}
vector<int64_t> cnt(10, 0);
for (auto &&c : s)
{
cnt[c - '0']++;
}
set<int64_t> st;
for (int64_t a = 0; a < 10; a++)
{
for (int64_t b = 0; b < 10; b++)
{
for (int64_t c = 0; c < 10; c++)
{
cnt[a]--;
cnt[b]--;
cnt[c]--;
if (cnt[a] < 0 || cnt[b] < 0 || cnt[c] < 0)
{
cnt[a]++;
cnt[b]++;
cnt[c]++;
continue;
}
st.insert((100 * a + 10 * b + c) % 40);
cnt[a]++;
cnt[b]++;
cnt[c]++;
}
}
}
cout << st.size() << endl;
return 0;
}
ldsyb