Submission #91361

# Submission time Handle Problem Language Result Execution time Memory
91361 2018-12-27T08:51:44 Z YottaByte Marriage questions (IZhO14_marriage) C++14
14 / 100
1500 ms 9776 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;
}
int f;
void check(int l, int cur, int p)
{
	if(f) return;
	if(p == tr)
	{
		f = 1;
		d[l][cur] = 1;
		ans += (n - cur + 1);
		//puts("GOTCHA");
		//cout << cur << " " << t(p, 2) << endl << endl;
		return;
	}
	
	if(cur == n)
	{
		//puts("TRY\n");
		return;
	}
	
	int cho = 0;
	for(int i = 0; i < m; i++)
	{
		if(tb[i][cur])
		{
			cho |= (1 << i);
		}
	}
	
	//cout << l + 1 << " " << 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;
	}
	
	if(n < m)
	{
		puts("0");
		return 0;
	}
	
	tr = (1 << m) - 1;
	for(int l = 0; l < n; l++)
	{
		//puts("START");
		f = 0;
		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:71:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
marriage.cpp: In function 'int main()':
marriage.cpp:73: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:77: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 384 KB Output isn't correct
3 Incorrect 2 ms 560 KB Output isn't correct
4 Incorrect 2 ms 612 KB Output isn't correct
5 Correct 2 ms 612 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Incorrect 32 ms 672 KB Output isn't correct
8 Correct 2 ms 672 KB Output is correct
9 Correct 2 ms 672 KB Output is correct
10 Correct 2 ms 672 KB Output is correct
11 Correct 2 ms 776 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Incorrect 2 ms 776 KB Output isn't correct
14 Incorrect 11 ms 776 KB Output isn't correct
15 Incorrect 2 ms 804 KB Output isn't correct
16 Incorrect 2 ms 804 KB Output isn't correct
17 Incorrect 4 ms 804 KB Output isn't correct
18 Incorrect 2 ms 804 KB Output isn't correct
19 Execution timed out 1558 ms 804 KB Time limit exceeded
20 Execution timed out 1541 ms 804 KB Time limit exceeded
21 Execution timed out 1564 ms 804 KB Time limit exceeded
22 Execution timed out 1566 ms 804 KB Time limit exceeded
23 Execution timed out 1576 ms 992 KB Time limit exceeded
24 Execution timed out 1581 ms 1000 KB Time limit exceeded
25 Execution timed out 1567 ms 1264 KB Time limit exceeded
26 Execution timed out 1580 ms 1264 KB Time limit exceeded
27 Execution timed out 1570 ms 1264 KB Time limit exceeded
28 Execution timed out 1573 ms 1264 KB Time limit exceeded
29 Execution timed out 1580 ms 1500 KB Time limit exceeded
30 Execution timed out 1574 ms 1500 KB Time limit exceeded
31 Execution timed out 1579 ms 2396 KB Time limit exceeded
32 Execution timed out 1562 ms 2396 KB Time limit exceeded
33 Execution timed out 1576 ms 2396 KB Time limit exceeded
34 Execution timed out 1580 ms 2396 KB Time limit exceeded
35 Execution timed out 1579 ms 2568 KB Time limit exceeded
36 Execution timed out 1577 ms 3188 KB Time limit exceeded
37 Execution timed out 1580 ms 4624 KB Time limit exceeded
38 Execution timed out 1560 ms 4776 KB Time limit exceeded
39 Execution timed out 1582 ms 7248 KB Time limit exceeded
40 Execution timed out 1574 ms 7248 KB Time limit exceeded
41 Execution timed out 1568 ms 7248 KB Time limit exceeded
42 Execution timed out 1575 ms 7248 KB Time limit exceeded
43 Execution timed out 1578 ms 7248 KB Time limit exceeded
44 Execution timed out 1567 ms 7632 KB Time limit exceeded
45 Execution timed out 1569 ms 8656 KB Time limit exceeded
46 Execution timed out 1569 ms 8912 KB Time limit exceeded
47 Execution timed out 1577 ms 9776 KB Time limit exceeded
48 Execution timed out 1573 ms 9776 KB Time limit exceeded
49 Execution timed out 1581 ms 9776 KB Time limit exceeded
50 Execution timed out 1573 ms 9776 KB Time limit exceeded