답안 #135403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135403 2019-07-24T04:54:52 Z 송준혁(#3252) PIN (CEOI10_pin) C++14
100 / 100
360 ms 632 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, D;
int A[101010];
int T[5] = {1, 40, 1600, 64000};
LL P[20];

int toint(char ch){
	if ('0' <= ch && ch <= '9') return ch - '0';
	return 10 + ch - 'a';
}

bool comp(int a, int b, int k){
	for (int i=0; i<4; i++){
		if ((k & (1<<i)) && a/T[i]%40 != b/T[i]%40) return a/T[i]%40 < b/T[i]%40;
	}
	return false;
}

int main(){
	scanf("%d %d", &N, &D);
	for (int i=1; i<=N; i++){
		for (int j=0; j<4; j++){
			char ch;
			scanf(" %c", &ch);
			A[i] = A[i]*40 + toint(ch);
		}
	}
	for (int i=1; i<15; i++){
		sort(A+1, A+N+1, [&](int a, int b){return comp(a, b, i);});
		LL p=1, q=1;
		while (p<=N){
			while (q < N && !comp(A[p], A[q+1], i) && !comp(A[q+1], A[p], i)) q++;
			P[i] += (q-p+1) * (q-p) / 2;
			p = q+1, q = p;
		}
	}
	if (D == 4) printf("%lld\n", (LL)N*(N-1)/2 - ((P[1]+P[2]+P[4]+P[8])-2*((P[3]+P[5]+P[9]+P[6]+P[10]+P[12])-3*(P[14]+P[13]+P[11]+P[7]))-3*(P[14]+P[13]+P[11]+P[7]))-((P[3]+P[5]+P[9]+P[6]+P[10]+P[12])-3*(P[14]+P[13]+P[11]+P[7]))-(P[14]+P[13]+P[11]+P[7]));
	if (D == 3) printf("%lld\n", (P[1]+P[2]+P[4]+P[8])-2*((P[3]+P[5]+P[9]+P[6]+P[10]+P[12])-3*(P[14]+P[13]+P[11]+P[7]))-3*(P[14]+P[13]+P[11]+P[7]));
	if (D == 2) printf("%lld\n", (P[3]+P[5]+P[9]+P[6]+P[10]+P[12])-3*(P[14]+P[13]+P[11]+P[7]));
	if (D == 1) printf("%lld\n", P[14]+P[13]+P[11]+P[7]);
	return 0;
}

Compilation message

pin.cpp: In function 'int main()':
pin.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &D);
  ~~~~~^~~~~~~~~~~~~~~~~
pin.cpp:28:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &ch);
    ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 376 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 9 ms 256 KB Output is correct
4 Correct 135 ms 504 KB Output is correct
5 Correct 165 ms 376 KB Output is correct
6 Correct 165 ms 380 KB Output is correct
7 Correct 136 ms 376 KB Output is correct
8 Correct 184 ms 376 KB Output is correct
9 Correct 306 ms 572 KB Output is correct
10 Correct 339 ms 632 KB Output is correct
11 Correct 177 ms 376 KB Output is correct
12 Correct 323 ms 508 KB Output is correct
13 Correct 200 ms 504 KB Output is correct
14 Correct 181 ms 504 KB Output is correct
15 Correct 330 ms 580 KB Output is correct
16 Correct 234 ms 504 KB Output is correct
17 Correct 358 ms 552 KB Output is correct
18 Correct 267 ms 504 KB Output is correct
19 Correct 319 ms 536 KB Output is correct
20 Correct 360 ms 588 KB Output is correct