Submission #483022

# Submission time Handle Problem Language Result Execution time Memory
483022 2021-10-27T12:14:45 Z DJeniUp Love Polygon (BOI18_polygon) C++17
100 / 100
197 ms 20796 KB
#pragma GCC Optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,pairll>pairlll;
typedef pair<pairll,pairll>pairllll;
typedef long double ld;
typedef pair<ll,string>pairls;

#define INF 1000000000000007
#define MOD 1000000007
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

ll n,d[100007],res,f[100007],a[100007];

map<string,ll>m;

string s1[100007],s2[100007];

priority_queue<pairll, vector<pairll>, greater<pairll> >q;

int main() {
    
    cin>>n;
    
    for(int i=1;i<=n;i++){
        cin>>s1[i]>>s2[i];
        m[s1[i]]=i;
    }
    if(n%2==1){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=1;i<=n;i++){
        d[i]=m[s2[i]];
        if(d[i]!=i)a[d[i]]++;
    }
    for(int i=1;i<=n;i++){
        if(d[d[i]]==i && d[i]!=i){
            f[i]=1;
        }else q.push({a[i],i});
    }
    while(q.size()>0){
        ll m1=q.top().fr;
        ll m2=q.top().sc;
        q.pop();
        if(f[m2]==0){
            f[m2]=1;
            if(d[m2]==m2){
                res++;
            }else{
                ll m3=d[m2];
                if(f[m3]==1){
                    res++;
                }else{
                    ll m4=d[m3];
                    res++;
                    a[m4]--;
                    f[m3]=1;
                    q.push({a[m4],m4});
                }
            }
        }
    }
    cout<<res<<endl;

}

Compilation message

polygon.cpp:1: warning: ignoring '#pragma GCC Optimize' [-Wunknown-pragmas]
    1 | #pragma GCC Optimize("O3")
      | 
polygon.cpp: In function 'int main()':
polygon.cpp:51:12: warning: unused variable 'm1' [-Wunused-variable]
   51 |         ll m1=q.top().fr;
      |            ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6476 KB Output is correct
2 Correct 3 ms 6476 KB Output is correct
3 Correct 4 ms 6476 KB Output is correct
4 Correct 3 ms 6476 KB Output is correct
5 Correct 3 ms 6476 KB Output is correct
6 Correct 4 ms 6560 KB Output is correct
7 Correct 3 ms 6476 KB Output is correct
8 Correct 3 ms 6556 KB Output is correct
9 Correct 5 ms 6476 KB Output is correct
10 Correct 3 ms 6476 KB Output is correct
11 Correct 3 ms 6476 KB Output is correct
12 Correct 3 ms 6476 KB Output is correct
13 Correct 3 ms 6476 KB Output is correct
14 Correct 3 ms 6552 KB Output is correct
15 Correct 3 ms 6476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6476 KB Output is correct
2 Correct 3 ms 6476 KB Output is correct
3 Correct 3 ms 6564 KB Output is correct
4 Correct 194 ms 20492 KB Output is correct
5 Correct 188 ms 20796 KB Output is correct
6 Correct 182 ms 20508 KB Output is correct
7 Correct 116 ms 16452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 20516 KB Output is correct
2 Correct 195 ms 20532 KB Output is correct
3 Correct 165 ms 19700 KB Output is correct
4 Correct 119 ms 16452 KB Output is correct
5 Correct 186 ms 20464 KB Output is correct
6 Correct 191 ms 20508 KB Output is correct
7 Correct 195 ms 20552 KB Output is correct
8 Correct 177 ms 20532 KB Output is correct
9 Correct 177 ms 20548 KB Output is correct
10 Correct 140 ms 19756 KB Output is correct
11 Correct 3 ms 6476 KB Output is correct
12 Correct 3 ms 6476 KB Output is correct
13 Correct 3 ms 6476 KB Output is correct
14 Correct 3 ms 6476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6476 KB Output is correct
2 Correct 3 ms 6476 KB Output is correct
3 Correct 4 ms 6476 KB Output is correct
4 Correct 3 ms 6476 KB Output is correct
5 Correct 3 ms 6476 KB Output is correct
6 Correct 4 ms 6560 KB Output is correct
7 Correct 3 ms 6476 KB Output is correct
8 Correct 3 ms 6556 KB Output is correct
9 Correct 5 ms 6476 KB Output is correct
10 Correct 3 ms 6476 KB Output is correct
11 Correct 3 ms 6476 KB Output is correct
12 Correct 3 ms 6476 KB Output is correct
13 Correct 3 ms 6476 KB Output is correct
14 Correct 3 ms 6552 KB Output is correct
15 Correct 3 ms 6476 KB Output is correct
16 Correct 3 ms 6476 KB Output is correct
17 Correct 3 ms 6476 KB Output is correct
18 Correct 3 ms 6564 KB Output is correct
19 Correct 194 ms 20492 KB Output is correct
20 Correct 188 ms 20796 KB Output is correct
21 Correct 182 ms 20508 KB Output is correct
22 Correct 116 ms 16452 KB Output is correct
23 Correct 184 ms 20516 KB Output is correct
24 Correct 195 ms 20532 KB Output is correct
25 Correct 165 ms 19700 KB Output is correct
26 Correct 119 ms 16452 KB Output is correct
27 Correct 186 ms 20464 KB Output is correct
28 Correct 191 ms 20508 KB Output is correct
29 Correct 195 ms 20552 KB Output is correct
30 Correct 177 ms 20532 KB Output is correct
31 Correct 177 ms 20548 KB Output is correct
32 Correct 140 ms 19756 KB Output is correct
33 Correct 3 ms 6476 KB Output is correct
34 Correct 3 ms 6476 KB Output is correct
35 Correct 3 ms 6476 KB Output is correct
36 Correct 3 ms 6476 KB Output is correct
37 Correct 187 ms 20564 KB Output is correct
38 Correct 184 ms 20532 KB Output is correct
39 Correct 186 ms 20776 KB Output is correct
40 Correct 179 ms 20532 KB Output is correct
41 Correct 192 ms 20568 KB Output is correct
42 Correct 191 ms 20544 KB Output is correct
43 Correct 186 ms 20532 KB Output is correct
44 Correct 187 ms 20500 KB Output is correct
45 Correct 183 ms 20612 KB Output is correct
46 Correct 192 ms 20560 KB Output is correct
47 Correct 173 ms 20528 KB Output is correct
48 Correct 197 ms 20580 KB Output is correct
49 Correct 184 ms 20556 KB Output is correct
50 Correct 166 ms 19764 KB Output is correct
51 Correct 116 ms 16444 KB Output is correct
52 Correct 185 ms 20660 KB Output is correct
53 Correct 179 ms 20532 KB Output is correct
54 Correct 177 ms 20544 KB Output is correct
55 Correct 177 ms 20508 KB Output is correct
56 Correct 173 ms 20532 KB Output is correct
57 Correct 143 ms 19808 KB Output is correct
58 Correct 3 ms 6476 KB Output is correct
59 Correct 3 ms 6476 KB Output is correct
60 Correct 3 ms 6476 KB Output is correct
61 Correct 3 ms 6476 KB Output is correct
62 Correct 3 ms 6476 KB Output is correct
63 Correct 3 ms 6476 KB Output is correct
64 Correct 3 ms 6476 KB Output is correct
65 Correct 186 ms 20532 KB Output is correct
66 Correct 177 ms 20760 KB Output is correct
67 Correct 179 ms 20532 KB Output is correct
68 Correct 130 ms 16468 KB Output is correct
69 Correct 4 ms 6476 KB Output is correct
70 Correct 4 ms 6476 KB Output is correct
71 Correct 3 ms 6476 KB Output is correct
72 Correct 3 ms 6476 KB Output is correct
73 Correct 3 ms 6476 KB Output is correct
74 Correct 3 ms 6476 KB Output is correct
75 Correct 3 ms 6476 KB Output is correct
76 Correct 3 ms 6476 KB Output is correct
77 Correct 3 ms 6476 KB Output is correct
78 Correct 3 ms 6476 KB Output is correct
79 Correct 4 ms 6476 KB Output is correct
80 Correct 4 ms 6476 KB Output is correct
81 Correct 3 ms 6476 KB Output is correct
82 Correct 3 ms 6476 KB Output is correct
83 Correct 3 ms 6476 KB Output is correct