結果
| 問題 |
No.2178 Payable Magic Items
|
| コンテスト | |
| ユーザー |
MasKoaTS
|
| 提出日時 | 2022-12-31 17:35:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 714 ms / 4,000 ms |
| コード長 | 2,747 bytes |
| コンパイル時間 | 4,498 ms |
| コンパイル使用メモリ | 261,896 KB |
| 最終ジャッジ日時 | 2025-02-09 22:24:52 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
#include <math.h>
#include <bits/stdc++.h>
#include <atcoder/all>
#pragma warning(disable: 4996)
using namespace std;
using namespace atcoder;
#define print(n) cout << (n) << endl
#define fprint(n) cout << setprecision(16) << (n) << endl
#define ceil_div(a, b) (((a) - 1) / (b) + 1)
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define itrep(itr, st) for (auto itr = st.begin(); itr != st.end(); itr++)
#define ite(i, a) for (auto& i : a)
#define last(v) v[v.size() - 1]
#define all(x) x.begin(), x.end()
#define lb(A, x) (lower_bound(all(A), x) - A.begin())
#define ub(A, x) (upper_bound(all(A), x) - A.begin())
#define INF 4611686018427387903ll
#define inf 2147483647
#define mod 1000000007ll
#define MOD 998244353ll
using str = string;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using Pair = pair<int, int>;
using mint = modint1000000007;
using Mint = modint998244353;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T> >;
template <class T> using PQ = priority_queue<T, V<T>, greater<T> >;
template <class T> using PQR = priority_queue<T>;
template <class T> using BIT = fenwick_tree<T>;
template <class T> inline V<T> getList(int n) { V<T> res(n); rep(i, 0, n) { cin >> res[i]; }return res; }
template <class T> inline VV<T> getGrid(int m, int n) { VV<T> res(m, V<T>(n)); rep(i, 0, m) { res[i] = getList<T>(n); }return res; }
template <class T> inline void prints(V<T>& vec) { if (vec.size() == 0)return; cout << vec[0]; rep(i, 1, vec.size()) { cout << ' ' << vec[i]; } cout << '\n'; }
template<class T> inline vector<tuple<size_t, T> > enumerate(const vector<T>& values) { auto length = values.size(); auto values_with_indices = vector<tuple<size_t, T>>(length); for (size_t i = 0; i < length; ++i) { values_with_indices[i] = make_tuple(i, values[i]); } return values_with_indices; }
inline V<int> dtois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - '0'); } return vec; }
inline V<int> atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'a'); } return vec; }
inline V<int> Atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'A'); } return vec; }
int main(void) {
ll N, K; cin >> N >> K;
V<str> s = getList<str>(N);
unordered_set<str> st = {};
for (str start : s) {
if (st.find(start) != st.end()) {
continue;
}
V<str> stk = { start };
while (stk.empty() == false) {
str v = last(stk); stk.pop_back();
rep(i, 0, K) {
str nv = v;
if (nv[i] == '0') {
continue;
}
nv[i]--;
if (st.find(nv) != st.end()) {
continue;
}
st.insert(nv);
stk.push_back(nv);
}
}
}
ll ans = 0;
for (str ss : s) {
ans += (st.find(ss) != st.end());
}
print(ans);
return 0;
}
MasKoaTS