結果
| 問題 |
No.2178 Payable Magic Items
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-07 23:36:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 609 ms / 4,000 ms |
| コード長 | 1,299 bytes |
| コンパイル時間 | 1,333 ms |
| コンパイル使用メモリ | 126,936 KB |
| 最終ジャッジ日時 | 2025-02-24 16:41:19 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
#include<unordered_set>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
ll dp[6][6][6][6][6][6][6][6];
int main(){
int N,K;
cin>>N>>K;
vector<string> S(N);
for(int i=0;i<N;i++){
cin>>S[i];
}
unordered_set<string> visited;
for(auto s:S){
if(visited.count(s)){
continue;
}
vector<string> stk;
stk.push_back(s);
while(!stk.empty()){
string s=stk.back();
stk.pop_back();
for(int i=0;i<K;i++){
int a=(s[i]-'0');
if(a==0) continue;
string nv=s;
nv[i]=(char)(a-1+'0');
if(visited.count(nv)==0){
stk.push_back(nv);
visited.insert(nv);
}
}
}
}
int ans=0;
for(string s:S){
if(visited.count(s)){
ans++;
}
}
cout<<ans<<endl;
}