Submission #91355

# Submission time Handle Problem Language Result Execution time Memory
91355 2018-12-27T08:38:17 Z YottaByte Marriage questions (IZhO14_marriage) C++14
14 / 100
1500 ms 4732 KB
#include <stdio.h>
#include <iostream>
using namespace std;

#define pb push_back
#define ll long long
#define fr first
#define sc second
#define mk make_pair

const int N = 1000;
const int M = 500;

int n, m, k, ans, d[N + 1][N + 1];
int tr, tb[N + 1][M + 1];

string t(int a, int b)
{
	string res = "";
	while(a)
	{
		res += char((a % b) + '0');
		a /= b;
	}
	
	while(res.size() < m)
		res += '0';
	
	return res;
}

void check(int l, int cur, int p)
{
	if(d[l][cur])
	{
		//puts("BEEN HERE\n");
		return;
	}
	
	if(p == tr)
	{
		d[l][cur] = 1;
		ans += (n - cur + 1);
		//puts("GOTCHA");
		//cout << cur << " " << t(p, 2) << endl << endl;
		return;
	}
	
	if(cur == n)
	{
		//found = true;
		//puts("TRY\n");
		return;
	}
	
	int cho = 0;
	for(int i = 0; i < m; i++)
	{
		if(tb[i][cur])
		{
			cho |= (1 << i);
		}
	}
	
	//cout << l << " " << cur + 1 << " " << t(cho, 2) << " " << t(p, 2) << endl;
	
	for(int i = 0; i < m; i++)
	{
		if((cho >> i) & 1)
		{
			check(l, cur + 1, (cho & (1 << i)) | p);
		}
	}
}

main()
{
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 0; i < k; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		
		a--, b--;
		tb[b][a] = 1;
	}
	
	//for(int j = 0; j < n * 2; j++)
		//cout << '-';
	//puts("");
	//for(int i = 0; i < m; i++)
	//{
		//for(int j = 0; j < n; j++)
		//{
			//if(tb[i][j]) cout << "+";
			//else cout << " ";
			//cout << "|";
		//}
		//puts("");
		
		//for(int j = 0; j < n * 2; j++)
			//cout << '-';
		//puts("");
	//}
	
	if(n < m)
	{
		puts("0");
		return 0;
	}
	
	tr = (1 << m) - 1;
	for(int l = 0; l < n; l++)
	{
		//puts("START");
		check(l, l, 0);
	}
	
	printf("%d", ans);
}
/**

5 3 7
1 1
1 2
1 3
2 3
3 2
4 2
5 1

**/

Compilation message

marriage.cpp: In function 'std::__cxx11::string t(int, int)':
marriage.cpp:26:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(res.size() < m)
        ~~~~~~~~~~~^~~
marriage.cpp: At global scope:
marriage.cpp:76:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
marriage.cpp: In function 'int main()':
marriage.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &m, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
marriage.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 1 ms 408 KB Output isn't correct
4 Incorrect 2 ms 408 KB Output isn't correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 2 ms 456 KB Output is correct
7 Incorrect 443 ms 596 KB Output isn't correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Incorrect 2 ms 596 KB Output isn't correct
14 Incorrect 109 ms 596 KB Output isn't correct
15 Incorrect 5 ms 596 KB Output isn't correct
16 Incorrect 2 ms 596 KB Output isn't correct
17 Incorrect 28 ms 660 KB Output isn't correct
18 Incorrect 4 ms 660 KB Output isn't correct
19 Execution timed out 1567 ms 660 KB Time limit exceeded
20 Execution timed out 1586 ms 660 KB Time limit exceeded
21 Execution timed out 1579 ms 752 KB Time limit exceeded
22 Execution timed out 1576 ms 752 KB Time limit exceeded
23 Execution timed out 1567 ms 752 KB Time limit exceeded
24 Execution timed out 1559 ms 752 KB Time limit exceeded
25 Execution timed out 1571 ms 1004 KB Time limit exceeded
26 Execution timed out 1563 ms 1004 KB Time limit exceeded
27 Execution timed out 1567 ms 1004 KB Time limit exceeded
28 Execution timed out 1580 ms 1004 KB Time limit exceeded
29 Execution timed out 1565 ms 1004 KB Time limit exceeded
30 Execution timed out 1580 ms 1004 KB Time limit exceeded
31 Execution timed out 1570 ms 1660 KB Time limit exceeded
32 Execution timed out 1563 ms 1660 KB Time limit exceeded
33 Execution timed out 1565 ms 1660 KB Time limit exceeded
34 Execution timed out 1582 ms 1660 KB Time limit exceeded
35 Execution timed out 1579 ms 1660 KB Time limit exceeded
36 Execution timed out 1581 ms 1660 KB Time limit exceeded
37 Execution timed out 1569 ms 2556 KB Time limit exceeded
38 Execution timed out 1570 ms 2684 KB Time limit exceeded
39 Execution timed out 1552 ms 4476 KB Time limit exceeded
40 Execution timed out 1577 ms 4476 KB Time limit exceeded
41 Execution timed out 1566 ms 4476 KB Time limit exceeded
42 Execution timed out 1560 ms 4476 KB Time limit exceeded
43 Execution timed out 1570 ms 4476 KB Time limit exceeded
44 Execution timed out 1550 ms 4604 KB Time limit exceeded
45 Execution timed out 1558 ms 4604 KB Time limit exceeded
46 Execution timed out 1571 ms 4604 KB Time limit exceeded
47 Execution timed out 1560 ms 4732 KB Time limit exceeded
48 Execution timed out 1545 ms 4732 KB Time limit exceeded
49 Execution timed out 1566 ms 4732 KB Time limit exceeded
50 Execution timed out 1562 ms 4732 KB Time limit exceeded