# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
856482 | MilosMilutinovic | PIN (CEOI10_pin) | C++14 | 350 ms | 14820 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int readint(){
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,d;
char s[50005][4];
int main(){
scanf("%d%d",&n,&d); d=4-d;
for(int i=1;i<=n;i++) scanf("%s",s+i);
map<string,int> cnt;
long long ans=0;
for(int i=1;i<=n;i++){
for(int mask=(1<<4)-1;mask>=0;mask--){
int pc=__builtin_popcount(mask);
if(pc<d) continue;
string str="";
for(int j=0;j<4;j++) if(mask>>j&1) str+=s[i][j]; else str+='*';
if (d==4){
ans+=cnt[str];
continue;
}
if (d==3){
if(pc==4) ans-=4*cnt[str];
if(pc==3) ans+=cnt[str];
continue;
}
if(d==2){
if(pc==3) ans-=3*cnt[str];
if(pc==2) ans+=cnt[str];
continue;
}
if(d==1){
if(pc==2) ans-=2*cnt[str];
if(pc==1) ans+=cnt[str];
continue;
}
ans+=cnt[str]*(d%2==pc%2?1:-1);
}
for(int mask=0;mask<(1<<4);mask++){
string str="";
for(int j=0;j<4;j++) if(mask>>j&1) str+=s[i][j]; else str+='*';
cnt[str]+=1;
}
}
printf("%lld\n",ans);
return 0;
}
/*
4 1
0000
a010
0202
a0e2
4 2
0000
a010
0202
a0e2
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |