답안 #1053071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053071 2024-08-11T08:28:51 Z tolbi 분수 공원 (IOI21_parks) C++17
15 / 100
292 ms 31284 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
//void build(std::vector<int> u, std::vector<int> v, std::vector<int> a, std::vector<int> b);
struct DSU{
    vector<int> par;
    int tot;
    DSU(int n):tot(n){
        par.resize(n);
        iota(par.begin(), par.end(), 0);
    }
    int find(int node){
        if (par[node]==node) return node;
        return par[node]=find(par[node]);
    }
    bool merge(int a, int b){
        a=find(a);
        b=find(b);
        if (a!=b) tot--;
        else return false;
        par[a]=b;
        return true;
    }
};
int construct_roads(vector<int> x, vector<int> y) {
    bool subtask3 = true;
    int n = x.size();
    map<pair<int,int>,int> mp;
    for (int i = 0; i < n; i++){
        mp[{x[i],y[i]}]=i;
        if (x[i]<2 || x[i]>6) subtask3=false;
    }
    if (subtask3){
        DSU dsu(n);
        vector<int> u;
        vector<int> v;
        vector<int> xa;
        vector<int> ya;
        set<pair<int,int>> occupied;
        vector<int> lol;
        for (int i = 0; i < n; i++){
            if (mp.count({x[i],y[i]-2})){
                if (dsu.merge(i,mp[{x[i],y[i]-2}])){
                    u.push_back(mp[{x[i],y[i]-2}]);
                    v.push_back(i);
                    ya.push_back(y[i]-1);
                    if (x[i]==2) xa.push_back(x[i]-1);
                    else if (x[i]==6) xa.push_back(x[i]+1);
                    else {
                        xa.push_back(-1);
                        lol.push_back(x[i]);
                    }
                    if (xa.back()!=-1) occupied.insert({xa.back(),ya.back()});
                }
            }
        }
        for (int i = 0; i < n; ++i)
        {
            if (mp.count({x[i]-2,y[i]})){
                if (dsu.merge(i,mp[{x[i]-2,y[i]}])){
                    u.push_back(mp[{x[i]-2,y[i]}]);
                    v.push_back(i);
                    xa.push_back(x[i]-1);
                    if (x[i]==6) ya.push_back(y[i]-1);
                    else ya.push_back(y[i]-1);
                    occupied.insert({xa.back(),ya.back()});
                }
            }
        }
        reverse(lol.begin(), lol.end());
        bool boolean=true;
        for (int i = 0; i < xa.size(); i++){
            if (xa[i]==-1){
                if (occupied.find({lol.back()+1,ya[i]})==occupied.end()){
                    xa[i]=lol.back()+1;
                }
                else if (occupied.find({lol.back()-1,ya[i]})==occupied.end()){
                    xa[i]=lol.back()-1;
                }
                else {
                    boolean=false;
                    break;
                }
                lol.pop_back();
            }
        }
        if (dsu.tot==1 && boolean) {
            return build(u,v,xa,ya),1;
        }
        return 0;
    }
    else return cout<<"WA"<<endl,0;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int i = 0; i < xa.size(); i++){
      |                         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 126 ms 18028 KB Output is correct
10 Correct 6 ms 2392 KB Output is correct
11 Correct 38 ms 9932 KB Output is correct
12 Correct 9 ms 3160 KB Output is correct
13 Correct 25 ms 6860 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 124 ms 17936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 126 ms 18028 KB Output is correct
10 Correct 6 ms 2392 KB Output is correct
11 Correct 38 ms 9932 KB Output is correct
12 Correct 9 ms 3160 KB Output is correct
13 Correct 25 ms 6860 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 124 ms 17936 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 292 ms 31284 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 94 ms 12764 KB Output is correct
29 Correct 152 ms 19000 KB Output is correct
30 Correct 231 ms 25000 KB Output is correct
31 Correct 290 ms 31140 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 118 ms 16512 KB Output is correct
46 Correct 189 ms 23916 KB Output is correct
47 Correct 198 ms 23716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 126 ms 18028 KB Output is correct
10 Correct 6 ms 2392 KB Output is correct
11 Correct 38 ms 9932 KB Output is correct
12 Correct 9 ms 3160 KB Output is correct
13 Correct 25 ms 6860 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 124 ms 17936 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 292 ms 31284 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 94 ms 12764 KB Output is correct
29 Correct 152 ms 19000 KB Output is correct
30 Correct 231 ms 25000 KB Output is correct
31 Correct 290 ms 31140 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 118 ms 16512 KB Output is correct
46 Correct 189 ms 23916 KB Output is correct
47 Correct 198 ms 23716 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Incorrect 0 ms 348 KB Solution announced impossible, but it is possible.
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 126 ms 18028 KB Output is correct
10 Correct 6 ms 2392 KB Output is correct
11 Correct 38 ms 9932 KB Output is correct
12 Correct 9 ms 3160 KB Output is correct
13 Correct 25 ms 6860 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 124 ms 17936 KB Output is correct
17 Incorrect 0 ms 348 KB Possible tampering with the output
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 126 ms 18028 KB Output is correct
10 Correct 6 ms 2392 KB Output is correct
11 Correct 38 ms 9932 KB Output is correct
12 Correct 9 ms 3160 KB Output is correct
13 Correct 25 ms 6860 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 124 ms 17936 KB Output is correct
17 Incorrect 87 ms 15952 KB Possible tampering with the output
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 126 ms 18028 KB Output is correct
10 Correct 6 ms 2392 KB Output is correct
11 Correct 38 ms 9932 KB Output is correct
12 Correct 9 ms 3160 KB Output is correct
13 Correct 25 ms 6860 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 124 ms 17936 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 292 ms 31284 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 94 ms 12764 KB Output is correct
29 Correct 152 ms 19000 KB Output is correct
30 Correct 231 ms 25000 KB Output is correct
31 Correct 290 ms 31140 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 118 ms 16512 KB Output is correct
46 Correct 189 ms 23916 KB Output is correct
47 Correct 198 ms 23716 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Incorrect 0 ms 348 KB Solution announced impossible, but it is possible.
52 Halted 0 ms 0 KB -