제출 #1322853

#제출 시각아이디문제언어결과실행 시간메모리
1322853lorrelfPIN (CEOI10_pin)C++20
20 / 100
1099 ms113068 KiB
//Beiba.cpp rulit! #include <bits/stdc++.h> using namespace std; #define open freopen ("sum.in","r",stdin), freopen ("sum.out","w",stdout); #define nl '\n' #define ll long long int #define pb push_back #define sz size() #define all(x) x.begin(), x.end() #define S second #define F first #define co continue #define NO cout<<"NO"<<nl #define YES cout<<"YES"<<nl #define No cout<<"No"<<nl #define Yes cout<<"Yes"<<nl #define rt return #define str string #define pot fixed<<setprecision #define int ll #define pi pair<int,int> #define vi vector #define MAI INT64_MAX #define MII INT64_MIN const int inf=1e18, mod=1e9+7, N=3e5+7; int n,d,ans; str a[N]; map <str,int> cnt; void dr1(int idx){ str s=a[idx]; for(int pos=0; pos<4; pos++){ for(char buk='0'; buk<='9'; buk++){ s[pos]=buk; if(s==a[idx]) co; ans+=cnt[s]; } for(char buk='a'; buk<='z'; buk++){ s[pos]=buk; if(s==a[idx]) co; ans+=cnt[s]; } s=a[idx]; } } int dr2(int idx){ str s=a[idx]; int res=0; for(int pos=0; pos<4; pos++){ for(char buk='0'; buk<='9'; buk++){ s[pos]=buk; if(buk==a[idx][pos]) co; for(int pos2=0; pos2<4; pos2++){ if(pos==pos2) co; for(char buk2='0'; buk2<='9'; buk2++){ s[pos2]=buk2; if(buk2==a[idx][pos2]) co; res+=cnt[s]; } for(char buk2='a'; buk2<='z'; buk2++){ s[pos2]=buk2; if(buk2==a[idx][pos2]) co; res+=cnt[s]; } s=a[idx]; s[pos]=buk; } } s=a[idx]; for(char buk='a'; buk<='z'; buk++){ s[pos]=buk; if(buk==a[idx][pos]) co; for(int pos2=0; pos2<4; pos2++){ if(pos==pos2) co; for(char buk2='0'; buk2<='9'; buk2++){ s[pos2]=buk2; if(buk2==a[idx][pos2]) co; res+=cnt[s]; } for(char buk2='a'; buk2<='z'; buk2++){ s[pos2]=buk2; if(buk2==a[idx][pos2]) co; res+=cnt[s]; } s=a[idx]; s[pos]=buk; } } s=a[idx]; } rt res; } void ibrosh_abi(){ cin>>n>>d; for(int i=1; i<=n; i++){ cin>>a[i]; cnt[a[i]]++; } sort(a+1,a+n+1); if(d==4){ cout<<(n*(n-1))/2<<nl; rt; } for(int i=1; i<=n; i++){ if(d==1) dr1(i); else if(d==2){ ans+=(dr2(i))/2; } } cout<<ans/2; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); //open int tt=1,cas=1; //cin>>tt; while(tt--){ //cout<<"Case "<<cas++<<": "; ibrosh_abi(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...