답안 #363286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
363286 2021-02-05T12:30:59 Z SamAnd 결혼 문제 (IZhO14_marriage) C++17
84 / 100
1500 ms 1132 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 30004, M = 2003;

int n, m, k;
vector<int> g[M];

int u[N];
int uu[M];
bool c[M];
bool dfs(int x, int l, int r)
{
    if (c[x])
        return false;
    c[x] = true;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        if (!(l <= h && h <= r))
            continue;
        if (u[h] == 0)
        {
            u[h] = x;
            uu[x] = h;
            return true;
        }
        else
        {
            if (dfs(u[h], l, r))
            {
                u[h] = x;
                uu[x] = h;
                return true;
            }
        }
    }
    return false;
}

void solv()
{
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < k; ++i)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        g[y].push_back(x);
    }

    int ans = 0;
    int r = 0;
    for (int l = 1; l <= n; ++l)
    {
        memset(u, 0, sizeof u);
        memset(uu, 0, sizeof uu);
        int i = 1;
        while (1)
        {
            while (1)
            {
                if (i == m + 1)
                    break;
                memset(c, false, sizeof c);
                if (dfs(i, l, r))
                {
                    ++i;
                    continue;
                }
                break;
            }
            if (i == m + 1)
                break;
            ++r;
            if (r == n + 1)
                break;
        }
        if (r == n + 1)
            break;
        ans += (n - r + 1);
    }
    printf("%d\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

Compilation message

marriage.cpp: In function 'bool dfs(int, int, int)':
marriage.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
marriage.cpp: In function 'void solv()':
marriage.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |     scanf("%d%d%d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
marriage.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 83 ms 620 KB Output is correct
26 Correct 26 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 19 ms 620 KB Output is correct
29 Correct 6 ms 492 KB Output is correct
30 Correct 5 ms 492 KB Output is correct
31 Correct 793 ms 892 KB Output is correct
32 Correct 14 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 484 ms 620 KB Output is correct
35 Execution timed out 1578 ms 1004 KB Time limit exceeded
36 Execution timed out 1581 ms 1004 KB Time limit exceeded
37 Execution timed out 1568 ms 876 KB Time limit exceeded
38 Correct 146 ms 1132 KB Output is correct
39 Execution timed out 1589 ms 748 KB Time limit exceeded
40 Correct 4 ms 620 KB Output is correct
41 Correct 819 ms 620 KB Output is correct
42 Correct 13 ms 620 KB Output is correct
43 Correct 19 ms 748 KB Output is correct
44 Correct 32 ms 1132 KB Output is correct
45 Execution timed out 1581 ms 748 KB Time limit exceeded
46 Execution timed out 1591 ms 1132 KB Time limit exceeded
47 Correct 51 ms 1004 KB Output is correct
48 Correct 35 ms 1004 KB Output is correct
49 Execution timed out 1571 ms 1132 KB Time limit exceeded
50 Execution timed out 1585 ms 748 KB Time limit exceeded