結果
| 問題 | No.2593 Reorder and Mod 120 | 
| コンテスト | |
| ユーザー |  a01sa01to | 
| 提出日時 | 2025-05-10 00:50:09 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 932 bytes | 
| コンパイル時間 | 3,388 ms | 
| コンパイル使用メモリ | 281,880 KB | 
| 実行使用メモリ | 7,844 KB | 
| 最終ジャッジ日時 | 2025-05-10 00:50:13 | 
| 合計ジャッジ時間 | 4,169 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 26 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  set<int> st;
  if (n < 8) {
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    do {
      int x = 0;
      rep(i, n) x = x * 10 + (s[p[i]] - '0');
      st.insert(x % 120);
    } while (next_permutation(p.begin(), p.end()));
  }
  else {
    vector<int> cnt(10, 0);
    rep(i, n) cnt[s[i] - '0']++;
    rep(i, 10) rep(j, 10) rep(k, 10) {
      cnt[i]--, cnt[j]--, cnt[k]--;
      if (cnt[i] >= 0 && cnt[j] >= 0 && cnt[k] >= 0) {
        int x = i * 100 + j * 10 + k;
        st.insert(x % 40);
      }
      cnt[i]++, cnt[j]++, cnt[k]++;
    }
  }
  cout << st.size() << '\n';
  return 0;
}
            
            
            
        