답안 #856487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856487 2023-10-03T16:31:05 Z MilosMilutinovic PIN (CEOI10_pin) C++14
100 / 100
336 ms 14672 KB
#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==3) ans+=3*cnt[str];
				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
*/

Compilation message

pin.cpp: In function 'int main()':
pin.cpp:25:32: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[4]' [-Wformat=]
   25 |  for(int i=1;i<=n;i++) scanf("%s",s+i);
      |                               ~^  ~~~
      |                                |   |
      |                                |   char (*)[4]
      |                                char*
pin.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d%d",&n,&d); d=4-d;
      |  ~~~~~^~~~~~~~~~~~~~
pin.cpp:25:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  for(int i=1;i<=n;i++) scanf("%s",s+i);
      |                        ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1368 KB Output is correct
2 Correct 7 ms 860 KB Output is correct
3 Correct 6 ms 848 KB Output is correct
4 Correct 77 ms 3464 KB Output is correct
5 Correct 97 ms 3672 KB Output is correct
6 Correct 118 ms 3632 KB Output is correct
7 Correct 92 ms 3408 KB Output is correct
8 Correct 106 ms 3892 KB Output is correct
9 Correct 185 ms 5484 KB Output is correct
10 Correct 251 ms 5764 KB Output is correct
11 Correct 123 ms 3924 KB Output is correct
12 Correct 248 ms 5488 KB Output is correct
13 Correct 167 ms 4180 KB Output is correct
14 Correct 146 ms 3896 KB Output is correct
15 Correct 286 ms 5568 KB Output is correct
16 Correct 162 ms 11068 KB Output is correct
17 Correct 314 ms 14672 KB Output is correct
18 Correct 271 ms 12276 KB Output is correct
19 Correct 335 ms 13648 KB Output is correct
20 Correct 336 ms 14660 KB Output is correct