Submission #951868

# Submission time Handle Problem Language Result Execution time Memory
951868 2024-03-22T21:18:59 Z Saul0906 PIN (CEOI10_pin) C++14
5 / 100
1000 ms 18856 KB
#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;
}

Compilation message

pin.cpp: In function 'void add(std::string)':
pin.cpp:2:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | #define rep(a,b,c) for(int a=b; a<c; a++)
......
   20 |  rep(i,0,s.size()){
      |      ~~~~~~~~~~~~                 
pin.cpp:20:2: note: in expansion of macro 'rep'
   20 |  rep(i,0,s.size()){
      |  ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1372 KB Output isn't correct
2 Incorrect 31 ms 1312 KB Output isn't correct
3 Correct 267 ms 1108 KB Output is correct
4 Incorrect 34 ms 8016 KB Output isn't correct
5 Incorrect 44 ms 9836 KB Output isn't correct
6 Incorrect 857 ms 10064 KB Output isn't correct
7 Incorrect 656 ms 8164 KB Output isn't correct
8 Incorrect 52 ms 11092 KB Output isn't correct
9 Incorrect 82 ms 16208 KB Output isn't correct
10 Execution timed out 1054 ms 12004 KB Time limit exceeded
11 Incorrect 929 ms 10624 KB Output isn't correct
12 Execution timed out 1057 ms 4240 KB Time limit exceeded
13 Execution timed out 1078 ms 3708 KB Time limit exceeded
14 Execution timed out 1050 ms 3156 KB Time limit exceeded
15 Execution timed out 1066 ms 3424 KB Time limit exceeded
16 Incorrect 57 ms 18856 KB Output isn't correct
17 Execution timed out 1065 ms 13292 KB Time limit exceeded
18 Execution timed out 1069 ms 3112 KB Time limit exceeded
19 Execution timed out 1055 ms 3304 KB Time limit exceeded
20 Execution timed out 1041 ms 3436 KB Time limit exceeded