# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91361 | YottaByte | Marriage questions (IZhO14_marriage) | C++14 | 1582 ms | 9776 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
**/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |