Submission #516021

# Submission time Handle Problem Language Result Execution time Memory
516021 2022-01-20T10:06:01 Z Be_dos Marriage questions (IZhO14_marriage) C++17
54 / 100
1500 ms 1048 KB
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <unordered_set>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <random>
#include <cfloat>
#include <chrono>
#include <bitset>
#include <complex>
#include <immintrin.h>
#include <cassert>

bool try_kuhn(int32_t v, bool* vis, std::vector<int32_t>* graph, int32_t* matched, int32_t left, int32_t right) {
    vis[v] = true;
    for(int32_t i = 0; i < graph[v].size(); i++)
        if(graph[v][i] >= left && graph[v][i] <= right && matched[graph[v][i]] == -1) {
            matched[graph[v][i]] = v;
            return true;
        }
    for(int32_t i = 0; i < graph[v].size(); i++)
        if(graph[v][i] >= left && graph[v][i] <= right && !vis[matched[graph[v][i]]] && try_kuhn(matched[graph[v][i]], vis, graph, matched, left, right)) {
            matched[graph[v][i]] = v;
            return true;
        }
    return false;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int32_t n, m, k;
    std::cin >> n >> m >> k;

    std::vector<int32_t>* graph = new std::vector<int32_t>[m];
    for(int32_t i = 0; i < k; i++) {
        int32_t src, dst;
        std::cin >> src >> dst;
        src--;
        dst--;
        //int32_t src = rand() % n, dst = rand() % m;

        graph[dst].push_back(src);
    }

    bool* vis = new bool[m];
    int32_t* matched = new int32_t[n];
    int32_t matched_cnt = 0;
    for(int32_t i = 0; i < n; i++)
        matched[i] = -1;

    int32_t ans = 0;
    for(int32_t i = 0; i < n; i++) {
        for(int32_t j = i; j < n; j++) {
            matched_cnt = 0;
            for(int32_t p = 0; p < n; p++)
                matched[p] = -1;
            for(int32_t p = 0; p < m; p++) {
                for(int32_t q = 0; q < m; q++)
                    vis[q] = false;
                if(try_kuhn(p, vis, graph, matched, i, j))
                    matched_cnt++;
            }
            if(matched_cnt == m)
                ans++;
        }
    }

    std::cout << ans << "\n";
    return 0;
}



Compilation message

marriage.cpp: In function 'bool try_kuhn(int32_t, bool*, std::vector<int>*, int32_t*, int32_t, int32_t)':
marriage.cpp:26:26: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int32_t i = 0; i < graph[v].size(); i++)
      |                        ~~^~~~~~~~~~~~~~~~~
marriage.cpp:31:26: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int32_t i = 0; i < graph[v].size(); i++)
      |                        ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 415 ms 332 KB Output is correct
20 Correct 60 ms 204 KB Output is correct
21 Correct 5 ms 204 KB Output is correct
22 Correct 5 ms 204 KB Output is correct
23 Correct 34 ms 296 KB Output is correct
24 Correct 29 ms 204 KB Output is correct
25 Execution timed out 1585 ms 332 KB Time limit exceeded
26 Execution timed out 1580 ms 332 KB Time limit exceeded
27 Correct 252 ms 304 KB Output is correct
28 Correct 231 ms 300 KB Output is correct
29 Execution timed out 1549 ms 332 KB Time limit exceeded
30 Correct 1454 ms 344 KB Output is correct
31 Execution timed out 1576 ms 600 KB Time limit exceeded
32 Execution timed out 1586 ms 380 KB Time limit exceeded
33 Execution timed out 1529 ms 332 KB Time limit exceeded
34 Execution timed out 1580 ms 332 KB Time limit exceeded
35 Execution timed out 1563 ms 976 KB Time limit exceeded
36 Execution timed out 1578 ms 812 KB Time limit exceeded
37 Execution timed out 1593 ms 640 KB Time limit exceeded
38 Execution timed out 1586 ms 844 KB Time limit exceeded
39 Execution timed out 1583 ms 572 KB Time limit exceeded
40 Execution timed out 1596 ms 460 KB Time limit exceeded
41 Execution timed out 1570 ms 460 KB Time limit exceeded
42 Execution timed out 1589 ms 460 KB Time limit exceeded
43 Execution timed out 1591 ms 588 KB Time limit exceeded
44 Execution timed out 1592 ms 844 KB Time limit exceeded
45 Execution timed out 1590 ms 716 KB Time limit exceeded
46 Execution timed out 1596 ms 1048 KB Time limit exceeded
47 Execution timed out 1586 ms 972 KB Time limit exceeded
48 Execution timed out 1567 ms 972 KB Time limit exceeded
49 Execution timed out 1595 ms 972 KB Time limit exceeded
50 Execution timed out 1595 ms 524 KB Time limit exceeded