Submission #157796

# Submission time Handle Problem Language Result Execution time Memory
157796 2019-10-13T02:49:43 Z imyujin PIN (CEOI10_pin) C++14
100 / 100
27 ms 1656 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long lint;

const int MAXN = 50010;

const int twoidx[6][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}};
const int thridx[4][3] = {{0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3}};
char S[MAXN][5];
int one[4][36], two[6][36][36], thr[4][36][36][36];

int gtwo(int j, int i) { return two[j][S[i][twoidx[j][0]]][S[i][twoidx[j][1]]]; }
int gthr(int j, int i) { return thr[j][S[i][thridx[j][0]]][S[i][thridx[j][1]]][S[i][thridx[j][2]]]; }

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, D;

	cin >> N >> D;
	for(int i = 0; i < N; i++) cin >> S[i];

	lint ans = 0;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < 4; j++) S[i][j] -= '0' <= S[i][j] && S[i][j] <= '9' ? '0' : ('a' - 10);
		int cnt[4] = {0, 0, 0, 0};
		for(int j = 0; j < 4; j++)
			cnt[3] += gthr(j, i);
		for(int j = 0; j < 6; j++) cnt[2] += gtwo(j, i);
		cnt[2] -= cnt[3] * 3;
		for(int j = 0; j < 4; j++) cnt[1] += one[j][S[i][j]];
		cnt[1] -= cnt[2] * 2 + cnt[3] * 3;
		cnt[0] = i - cnt[1] - cnt[2] - cnt[3];
		ans += cnt[4 - D];

		for(int j = 0; j < 4; j++) one[j][S[i][j]]++;
		for(int j = 0; j < 6; j++) two[j][S[i][twoidx[j][0]]][S[i][twoidx[j][1]]]++;
		for(int j = 0; j < 4; j++) thr[j][S[i][thridx[j][0]]][S[i][thridx[j][1]]][S[i][thridx[j][2]]]++;
	}
	cout << ans;
	return 0;
}

Compilation message

pin.cpp: In function 'int gtwo(int, int)':
pin.cpp:13:58: warning: array subscript has type 'char' [-Wchar-subscripts]
 int gtwo(int j, int i) { return two[j][S[i][twoidx[j][0]]][S[i][twoidx[j][1]]]; }
                                                          ^
pin.cpp:13:78: warning: array subscript has type 'char' [-Wchar-subscripts]
 int gtwo(int j, int i) { return two[j][S[i][twoidx[j][0]]][S[i][twoidx[j][1]]]; }
                                                                              ^
pin.cpp: In function 'int gthr(int, int)':
pin.cpp:14:58: warning: array subscript has type 'char' [-Wchar-subscripts]
 int gthr(int j, int i) { return thr[j][S[i][thridx[j][0]]][S[i][thridx[j][1]]][S[i][thridx[j][2]]]; }
                                                          ^
pin.cpp:14:78: warning: array subscript has type 'char' [-Wchar-subscripts]
 int gthr(int j, int i) { return thr[j][S[i][thridx[j][0]]][S[i][thridx[j][1]]][S[i][thridx[j][2]]]; }
                                                                              ^
pin.cpp:14:98: warning: array subscript has type 'char' [-Wchar-subscripts]
 int gthr(int j, int i) { return thr[j][S[i][thridx[j][0]]][S[i][thridx[j][1]]][S[i][thridx[j][2]]]; }
                                                                                                  ^
pin.cpp: In function 'int main()':
pin.cpp:31:54: warning: array subscript has type 'char' [-Wchar-subscripts]
   for(int j = 0; j < 4; j++) cnt[1] += one[j][S[i][j]];
                                                      ^
pin.cpp:36:44: warning: array subscript has type 'char' [-Wchar-subscripts]
   for(int j = 0; j < 4; j++) one[j][S[i][j]]++;
                                            ^
pin.cpp:37:55: warning: array subscript has type 'char' [-Wchar-subscripts]
   for(int j = 0; j < 6; j++) two[j][S[i][twoidx[j][0]]][S[i][twoidx[j][1]]]++;
                                                       ^
pin.cpp:37:75: warning: array subscript has type 'char' [-Wchar-subscripts]
   for(int j = 0; j < 6; j++) two[j][S[i][twoidx[j][0]]][S[i][twoidx[j][1]]]++;
                                                                           ^
pin.cpp:38:55: warning: array subscript has type 'char' [-Wchar-subscripts]
   for(int j = 0; j < 4; j++) thr[j][S[i][thridx[j][0]]][S[i][thridx[j][1]]][S[i][thridx[j][2]]]++;
                                                       ^
pin.cpp:38:75: warning: array subscript has type 'char' [-Wchar-subscripts]
   for(int j = 0; j < 4; j++) thr[j][S[i][thridx[j][0]]][S[i][thridx[j][1]]][S[i][thridx[j][2]]]++;
                                                                           ^
pin.cpp:38:95: warning: array subscript has type 'char' [-Wchar-subscripts]
   for(int j = 0; j < 4; j++) thr[j][S[i][thridx[j][0]]][S[i][thridx[j][1]]][S[i][thridx[j][2]]]++;
                                                                                               ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 6 ms 888 KB Output is correct
5 Correct 8 ms 1192 KB Output is correct
6 Correct 7 ms 1016 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 8 ms 1016 KB Output is correct
9 Correct 11 ms 1144 KB Output is correct
10 Correct 12 ms 1176 KB Output is correct
11 Correct 5 ms 1016 KB Output is correct
12 Correct 12 ms 1140 KB Output is correct
13 Correct 8 ms 1016 KB Output is correct
14 Correct 8 ms 1016 KB Output is correct
15 Correct 11 ms 1144 KB Output is correct
16 Correct 11 ms 1400 KB Output is correct
17 Correct 27 ms 1656 KB Output is correct
18 Correct 12 ms 1532 KB Output is correct
19 Correct 12 ms 1528 KB Output is correct
20 Correct 14 ms 1656 KB Output is correct