Submission #992394
Source Code Expand
#include<bits/stdc++.h> using namespace std; struct Bipartite_Matching { vector< vector< int > > graph; vector< int > match; vector< bool > used; Bipartite_Matching(int n) { graph.resize(n); } void add_edge(int u, int v) { graph[u].push_back(v); graph[v].push_back(u); } bool dfs(int v) { used[v] = true; for(int i = 0; i < graph[v].size(); i++) { int u = graph[v][i], w = match[u]; if(w == -1 || (!used[w] && dfs(w))) { match[v] = u; match[u] = v; return (true); } } return (false); } int bipartite_matching() { int ret = 0; match.assign(graph.size(), -1); for(int i = 0; i < graph.size(); i++) { if(match[i] == -1) { used.assign(graph.size(), false); ret += dfs(i); } } return (ret); } }; int main() { int N, M; int xs[100001] = {}; vector< int > ss[100001]; cin >> N >> M; int ret = 0; for(int i = 0; i < N; i++) { int X; cin >> X; X %= M; xs[X]++; ss[X].push_back(i); } Bipartite_Matching bp(N); for(int i = 0; i < M; i++) { if(i == M - i) { while(xs[i] - 2 >= 0) { xs[i] -= 2; ++ret; } continue; } for(int j = 0; j < min(xs[M - i], xs[i]); j++) { bp.add_edge(ss[M - i][j], ss[i][j]); } for(int j = 1; j < xs[i]; j++) { bp.add_edge(ss[i][j - 1], ss[i][j]); } } cout << bp.bipartite_matching() << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | ei13333 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1562 Byte |
Status | WA |
Exec Time | 2103 ms |
Memory | 12032 KB |
Judge Result
Set Name | sample | all | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 700 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
all | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 5 ms | 2944 KB |
01-02.txt | TLE | 2102 ms | 9976 KB |
01-03.txt | TLE | 2102 ms | 8316 KB |
01-04.txt | TLE | 2102 ms | 9976 KB |
01-05.txt | TLE | 2102 ms | 9088 KB |
01-06.txt | AC | 567 ms | 9728 KB |
01-07.txt | WA | 192 ms | 9344 KB |
01-08.txt | AC | 107 ms | 9472 KB |
01-09.txt | WA | 96 ms | 9472 KB |
01-10.txt | WA | 101 ms | 9984 KB |
01-11.txt | AC | 98 ms | 10368 KB |
01-12.txt | TLE | 2103 ms | 9848 KB |
01-13.txt | TLE | 2103 ms | 9976 KB |
01-14.txt | TLE | 2102 ms | 8208 KB |
01-15.txt | AC | 1567 ms | 9728 KB |
01-16.txt | WA | 100 ms | 9600 KB |
01-17.txt | AC | 92 ms | 9344 KB |
01-18.txt | AC | 95 ms | 9600 KB |
01-19.txt | AC | 94 ms | 9472 KB |
01-20.txt | AC | 94 ms | 12032 KB |
01-21.txt | TLE | 2102 ms | 8256 KB |
01-22.txt | AC | 1196 ms | 9856 KB |
01-23.txt | WA | 415 ms | 9472 KB |
01-24.txt | WA | 146 ms | 9472 KB |
01-25.txt | WA | 107 ms | 9472 KB |
01-26.txt | AC | 111 ms | 9472 KB |
01-27.txt | AC | 39 ms | 5888 KB |
01-28.txt | AC | 7 ms | 3200 KB |
01-29.txt | WA | 6 ms | 2944 KB |
01-30.txt | AC | 5 ms | 2944 KB |
sample-01.txt | AC | 5 ms | 2944 KB |
sample-02.txt | AC | 5 ms | 2944 KB |