답안 #128459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128459 2019-07-11T00:33:20 Z letrongdat 결혼 문제 (IZhO14_marriage) C++17
40 / 100
1500 ms 2348 KB
#include <bits/stdc++.h>
using namespace std;
#define forn(i, a, b)           for(int i=a; i<=b; ++i)
const int maxN = 3e4 +10;
const int maxM = 2e3 +10;
int matched[maxN];
vector<int> E[maxM];
int le, ri, t = 1;
int N, M, K;
long long result;
int visited[maxM];
vector<int> not_match;
bool visit(int u) {
    if (visited[u] == t) return false;
    visited[u] = t;
    while (E[u].back() < le) E[u].pop_back();
    for(auto v: E[u]) if (le <= v && v <= ri) {
        if (!matched[v] || visit(matched[v])) {
            matched[v] = u;
            return true;
        } 
    }
    return false;
}
int main() {
    ios::sync_with_stdio(0);
    cin >> N >> M >> K;
    forn(i, 1, K) {
        int Ai, Bi; 
        cin >> Ai >> Bi;
        E[Bi].push_back(Ai);
    }
    forn(i, 1, M) {
        sort(E[i].begin(), E[i].end());
        reverse(E[i].begin(), E[i].end());
    }
    forn(i, 1, M) not_match.push_back(i);
    for(le = 1; le <= N; ++le) {
        if (le > 1 && matched[le-1]) {
            not_match.push_back(matched[le-1]);
            matched[le-1] = 0;
        }
        while (ri < N && not_match.size()) {
            ri ++;
            t ++;
            while (not_match.size() && visit(not_match.back())) {
                t ++;
                not_match.pop_back();
            }
            
        }
        // cout << "check " << le << ' ' << ri << ' ' << matched[le] << '\n';
        // for(auto x: not_match) cout << x << ' ';
        // cout << '\n';
        // cout << "done\n";
        if (not_match.empty()) result += N-ri+1;
    }
    cout << result;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Correct 2 ms 376 KB Output is correct
5 Runtime error 3 ms 508 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Correct 3 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Correct 2 ms 376 KB Output is correct
23 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Correct 6 ms 504 KB Output is correct
26 Incorrect 3 ms 376 KB Output isn't correct
27 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Correct 2 ms 380 KB Output is correct
29 Incorrect 7 ms 508 KB Output isn't correct
30 Incorrect 6 ms 508 KB Output isn't correct
31 Correct 42 ms 1144 KB Output is correct
32 Incorrect 4 ms 504 KB Output isn't correct
33 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Correct 4 ms 504 KB Output is correct
35 Runtime error 87 ms 2348 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 76 ms 2300 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Correct 79 ms 1228 KB Output is correct
38 Execution timed out 1576 ms 1884 KB Time limit exceeded
39 Correct 76 ms 504 KB Output is correct
40 Runtime error 6 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Incorrect 8 ms 888 KB Output isn't correct
42 Incorrect 56 ms 888 KB Output isn't correct
43 Incorrect 97 ms 1244 KB Output isn't correct
44 Execution timed out 1586 ms 1916 KB Time limit exceeded
45 Incorrect 12 ms 1016 KB Output isn't correct
46 Incorrect 32 ms 2040 KB Output isn't correct
47 Incorrect 609 ms 2168 KB Output isn't correct
48 Incorrect 604 ms 1912 KB Output isn't correct
49 Incorrect 33 ms 2168 KB Output isn't correct
50 Correct 230 ms 644 KB Output is correct