# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
951868 | Saul0906 | PIN (CEOI10_pin) | C++14 | 1078 ms | 18856 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b; a<c; a++)
#define repa(a,b) for(auto a:b)
#define fi first
#define se second
#define pii pair<int, int>
#define ll long long
#define endl "\n"
using namespace std;
struct trie{
trie *nxt[36];
int cont=0;
} *TR = new trie;
void add(string s){
trie *act=TR;
int x;
rep(i,0,s.size()){
if(s[i]>'9' || s[i]<'0') x=s[i]-'a'+10;
else x=s[i]-'0';
if(!(act->nxt[x])) act->nxt[x]=new trie;
act=act->nxt[x];
act->cont++;
}
}
int solve(string s, int i, int x, trie *act){
if(!act || x<0 || 4-i<x) return 0;
if(i==4 || !x) return act->cont;
int ans=0;
rep(j,0,10){
if(j+'0'==s[i]) ans+=solve(s,i+1,x,act->nxt[j]);
else ans+=solve(s,i+1,x-1,act->nxt[j]);
}
rep(j,0,26){
if(j+'a'==s[i]) ans+=solve(s,i+1,x,act->nxt[j+10]);
else ans+=solve(s,i+1,x-1,act->nxt[j+10]);
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, d, ans=0;
cin>>n>>d;
string s[n];
rep(i,0,n){
cin>>s[i];
ans+=solve(s[i],0,d,TR);
add(s[i]);
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |