Submission #198719

# Submission time Handle Problem Language Result Execution time Memory
198719 2020-01-27T13:13:29 Z Neklixx PIN (CEOI10_pin) C++14
100 / 100
179 ms 12392 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define sh cin.tie(0); cin.sync_with_stdio(0); cout.tie(0);
#define FILE freopen("test.in", "r", stdin);
#define vprint(v) for (int ii = 0; ii < v.size(); ii++){cout << v[ii] << " ";}
#define debugv(v) if (v.size() != 0) {cout << "[ "; for (int __ = 0; __ < (int)(v.size()) - 1; __++){cout << v[__] << ", ";} cout << v[(int)(v.size()) - 1] << " ]" << endl;} else {cout << "[]" << endl;}
#define debug cout << "-----------------------------------------------" << endl;
#define print1(a) cout << "{ " << a << " }" << endl;
#define print2(a, b) cout << "{ " << a << ", " << b << " }" << endl;
#define print3(a, b, c) cout << "{ " << a << ", " << b << ", " << c << " }" << endl;
#define print4(a, b, c, d) cout << "{ " << a << ", " << b << ", " << c << ", " << d << " }" << endl;
using namespace std;
#define int long long
const int INF = 1e9 + 228;
const int MAXN = 1e3 + 28;
map<string, int> mapa[MAXN];

string to2(int x) {
	string res = "";
	while (x > 0) {
		res += (x % 2);
		x /= 2;
	}
	char zero = 0;
	while (res.size() < 4) {
		res += zero;
	}
	return res;
}
int n;
vector<string> v;
int calc(int d) {
	int ans = 0;
	for (int mask = 0; mask < (1 << 4); mask++) {
		string now = to2(mask);
		int sm = 0;
		for (int i = 0; i < now.size(); i++) {
			sm += now[i];
		}	
		if (sm != 4 - d)
			continue;
		for (int i = 0; i < n; i++) {
			string t = "";
			for (int j = 0; j < now.size(); j++) {
				if (now[j] == 0)
					continue;
				t += v[i][j];
			}
			mapa[mask][t]++;
		}
		for (auto to : mapa[mask]) {
			ans += ((to.S * (to.S - 1)) / 2);
		}
	}
	return ans;
}
signed main()
{
#ifdef LOCAL
    FILE;
#endif
    sh;
    int d;
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		v.pb(s);
	}    
	vector<int> c;
	c.pb(calc(1));
	c.pb(calc(2));
	c.pb(calc(3));
	c.pb(calc(4));
	//assert(d != 4);
	int ans = c[d - 1];
	//print1(ans);
	if (d == 2) {
		ans -= c[0] * 3;
	} else if (d == 3) {
		ans -= (c[1] - c[0] * 3) * 2;
		ans -= c[0] * 3;
	} else if (d == 4) {
		int d3 = c[2] - ((c[1] - c[0] * 3) * 2 + c[0] * 3);
		int d2 = (c[1] - c[0] * 3);
		ans -= (d3 + d2 + c[0]);
	}
	cout << ans << endl;
    return 0;
}

Compilation message

pin.cpp: In function 'long long int calc(long long int)':
pin.cpp:41:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < now.size(); i++) {
                   ~~^~~~~~~~~~~~
pin.cpp:48:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < now.size(); j++) {
                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1016 KB Output is correct
2 Correct 9 ms 1016 KB Output is correct
3 Correct 9 ms 892 KB Output is correct
4 Correct 50 ms 2416 KB Output is correct
5 Correct 59 ms 2540 KB Output is correct
6 Correct 59 ms 2540 KB Output is correct
7 Correct 49 ms 2416 KB Output is correct
8 Correct 63 ms 2832 KB Output is correct
9 Correct 99 ms 3180 KB Output is correct
10 Correct 107 ms 3428 KB Output is correct
11 Correct 62 ms 2668 KB Output is correct
12 Correct 106 ms 3236 KB Output is correct
13 Correct 68 ms 2672 KB Output is correct
14 Correct 64 ms 2668 KB Output is correct
15 Correct 102 ms 3304 KB Output is correct
16 Correct 121 ms 9580 KB Output is correct
17 Correct 179 ms 12392 KB Output is correct
18 Correct 137 ms 10340 KB Output is correct
19 Correct 155 ms 11496 KB Output is correct
20 Correct 172 ms 12264 KB Output is correct