Submission #217235

#TimeUsernameProblemLanguageResultExecution timeMemory
217235kartelMatching (COCI20_matching)C++14
11 / 110
505 ms47368 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #define F first #define S second #define pb push_back #define N +1000005 #define M ll(1e9 + 7) #define sz(x) (int)x.size() #define re return #define oo ll(1e18) #define el '\n' using namespace std; //using namespace __gnu_pbds; //typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; typedef long double ld; int x[N], y[N], n, i, mk[N], mask, j; vector <int> g[N], G[N]; int main() { // srand(time(0)); ios_base::sync_with_stdio(0); iostream::sync_with_stdio(0); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // in("data.in"); // out("data.out"); cin >> n; for (i = 0; i < n; i++) { cin >> x[i] >> y[i]; g[x[i]].pb(i); G[y[i]].pb(i); } for (mask = 0; mask < (1 << n); mask++) { vector <pair <int, int> > hor, ver; for (i = 0; i < n; i++) mk[i] = 0; for (i = 0; i < n; i++) { if (mask & (1 << i)) { if (g[x[i]].size() == 1) continue; int j = g[x[i]][1]; if (mk[j] || i == j) continue; hor.pb({i, j}); mk[i] = mk[j] = 1; } else { if (G[y[i]].size() == 1) continue; int j = G[y[i]][1]; if (mk[j] || i == j) continue; mk[i] = mk[j] = 1; ver.pb({i, j}); } } i = 0; while (i < n && mk[i]) i++; if (i < n) continue; bool f = 1; for (i = 0; i < hor.size(); i++) { int dx = min(x[hor[i].F], x[hor[i].S]); int dy = min(y[hor[i].F], y[hor[i].S]); int uy = max(y[hor[i].F], y[hor[i].S]); for (j = 0; j < ver.size(); j++) { int lx = min(x[ver[j].F], x[ver[j].S]); int rx = max(x[ver[j].F], x[ver[j].S]); int ly = min(y[ver[j].F], y[ver[j].S]); if (dx >= lx && dx <= rx && dy < ly && uy > ly) f = 0; } } if (!f) continue; cout << "DA" << el; for (auto x : hor) cout << x.F + 1 << " " << x.S + 1 << el; for (auto x : ver) cout << x.F + 1 << " " << x.S + 1 << el; return 0; } cout << "NE"; }

Compilation message (stderr)

matching.cpp: In function 'int main()':
matching.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < hor.size(); i++)
                     ~~^~~~~~~~~~~~
matching.cpp:80:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (j = 0; j < ver.size(); j++)
                             ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...