Submission #1031500

# Submission time Handle Problem Language Result Execution time Memory
1031500 2024-07-22T22:12:51 Z codexistent Love Polygon (BOI18_polygon) C++14
50 / 100
325 ms 33624 KB
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define f first
#define s second
 
int n, ec[MAXN];
string st[MAXN], nx[MAXN];
map<string, int> idx;
set<int> adj[MAXN];
set<pair<int, int>> se;
bool d[MAXN];
 
int main(){
    cin >> n;
    FOR(i, 1, n) ec[i] = 0;
    FOR(i, 1, n){
        cin >> st[i];
        idx.insert({st[i], i});
        cin >> nx[i];
    }
 
    if(n % 2) {
        cout << -1 << endl;
        return 0;
    }
 
    int r = 0;
    FOR(i, 1, n){
        d[i] = (idx[nx[idx[nx[i]]]] == i && idx[nx[i]] != i);
    }
 
    FOR(i, 1, n){
        if(i == idx[nx[i]] || d[i] || d[idx[nx[i]]]) continue;
        adj[i].insert(idx[nx[i]]);
        adj[idx[nx[i]]].insert(i);
    }
 
    int ct = 0;
    FOR(i, 1, n) if(!d[i]) ct++, se.insert({adj[i].size(), i});
 
    while(ct && se.size()){
        auto si = *se.begin();

        d[si.s] = true, ct--;
 
        if(si.f == 0){
            r++;
        }else{
            int j = 0, jmn = INT_MAX;
            for(int i : adj[si.s]){
                if(jmn > adj[i].size()) j = i, jmn = adj[i].size();
            }
            r++;
 
            se.erase({jmn, j});
            for(int j2 : adj[j]){
                se.erase({adj[j2].size(), j2});
                adj[j2].erase(j);
                se.insert({adj[j2].size(), j2});
            }
        }
 
        for(int i2 : adj[si.s]) {
            se.erase({adj[i2].size(), i2});
            adj[i2].erase(si.s);
            se.insert({adj[i2].size(), i2});
        }
 
        se.erase(se.begin());
    }

 
    cout << r << endl;
}

Compilation message

polygon.cpp: In function 'int main()':
polygon.cpp:53:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                 if(jmn > adj[i].size()) j = i, jmn = adj[i].size();
      |                    ~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11352 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 4 ms 11356 KB Output is correct
4 Correct 4 ms 11356 KB Output is correct
5 Correct 4 ms 11356 KB Output is correct
6 Correct 6 ms 11268 KB Output is correct
7 Correct 4 ms 11356 KB Output is correct
8 Correct 4 ms 11356 KB Output is correct
9 Correct 4 ms 11356 KB Output is correct
10 Correct 4 ms 11352 KB Output is correct
11 Correct 4 ms 11352 KB Output is correct
12 Correct 4 ms 11356 KB Output is correct
13 Correct 4 ms 11356 KB Output is correct
14 Correct 5 ms 11356 KB Output is correct
15 Correct 4 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11352 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 4 ms 11356 KB Output is correct
4 Correct 286 ms 33616 KB Output is correct
5 Incorrect 263 ms 32852 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 295 ms 33456 KB Output is correct
2 Correct 296 ms 33620 KB Output is correct
3 Correct 159 ms 24380 KB Output is correct
4 Correct 80 ms 19552 KB Output is correct
5 Correct 299 ms 33588 KB Output is correct
6 Correct 325 ms 33624 KB Output is correct
7 Correct 324 ms 33612 KB Output is correct
8 Correct 245 ms 28936 KB Output is correct
9 Correct 282 ms 33620 KB Output is correct
10 Correct 193 ms 33616 KB Output is correct
11 Correct 5 ms 11356 KB Output is correct
12 Correct 4 ms 11212 KB Output is correct
13 Correct 5 ms 11356 KB Output is correct
14 Correct 4 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11352 KB Output is correct
2 Correct 4 ms 11356 KB Output is correct
3 Correct 4 ms 11356 KB Output is correct
4 Correct 4 ms 11356 KB Output is correct
5 Correct 4 ms 11356 KB Output is correct
6 Correct 6 ms 11268 KB Output is correct
7 Correct 4 ms 11356 KB Output is correct
8 Correct 4 ms 11356 KB Output is correct
9 Correct 4 ms 11356 KB Output is correct
10 Correct 4 ms 11352 KB Output is correct
11 Correct 4 ms 11352 KB Output is correct
12 Correct 4 ms 11356 KB Output is correct
13 Correct 4 ms 11356 KB Output is correct
14 Correct 5 ms 11356 KB Output is correct
15 Correct 4 ms 11356 KB Output is correct
16 Correct 5 ms 11352 KB Output is correct
17 Correct 4 ms 11356 KB Output is correct
18 Correct 4 ms 11356 KB Output is correct
19 Correct 286 ms 33616 KB Output is correct
20 Incorrect 263 ms 32852 KB Output isn't correct
21 Halted 0 ms 0 KB -