Submission #329811

#TimeUsernameProblemLanguageResultExecution timeMemory
329811theshadow_04Love Polygon (BOI18_polygon)C++14
0 / 100
2021 ms10820 KiB
// V T An #include <bits/stdc++.h> #define F first #define S second #define MOD 1000000007 #define pb push_back #define ll long long #define Task "POLYGON" using namespace std; const int maxn = 100005; int n; int cap[maxn]; map<string, int> M; int cnt1 = 0, cnt2 = 0, cnt, a[maxn], b[maxn]; int ans = 2e9; void Solve(int t) { cnt1 = cnt2 = 0; for(int i = 0; i < cnt; ++i) { if((t >> i) & 1) a[++cnt1] = i + 1; else b[++cnt2] = i + 1; } do { int dem = 0; for(int i = 1; i <= cnt1; ++ i) { if(cap[a[i]] != b[i]) dem ++; if(cap[b[i]] != a[i]) dem ++; } ans = min(ans, dem); } while(next_permutation(b + 1, b + cnt2 + 1)); } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); if(fopen(Task".inp", "r")){ freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n; for(int i = 1; i <= n; ++i) { string s, t; cin >> s >> t; if(!M[s]) M[s] = ++ cnt; if(!M[t]) M[t] = ++ cnt; cap[M[s]] = M[t]; } if(cnt % 2) { cout << -1 << "\n"; return 0; } for(int i = 0; i < (1 << cnt); ++ i) { int x = __builtin_popcount(i); if(x != cnt / 2) continue; Solve(i); } if(ans == 2e9) ans = -1; cout << ans; } // CHY-AKAV

Compilation message (stderr)

polygon.cpp: In function 'int main()':
polygon.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   40 |   freopen(Task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
polygon.cpp:41:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   41 |   freopen(Task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...