結果

問題 No.2178 Payable Magic Items
コンテスト
ユーザー siman
提出日時 2023-04-28 14:23:44
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,601 ms / 4,000 ms
コード長 912 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,352 ms
コンパイル使用メモリ 152,320 KB
実行使用メモリ 40,304 KB
最終ジャッジ日時 2026-05-12 10:13:05
合計ジャッジ時間 22,228 ms
ジャッジサーバーID
(参考情報)
tmp-judge_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;

  vector<string> S(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }

  set<string> visited;

  for (string &s : S) {
    if (visited.count(s)) continue;

    queue<string> que;
    que.push(s);

    while (not que.empty()) {
      string str = que.front();
      que.pop();

      for (int i = 0; i < K; ++i) {
        if (str[i] == '0') continue;

        string ns = str;
        ns[i]--;

        if (visited.count(ns)) continue;
        visited.insert(ns);
        que.push(ns);
      }
    }
  }

  int ans = 0;
  for (string &s : S) {
    if (visited.count(s)) ++ans;
  }

  cout << ans << endl;

  return 0;
}
0