답안 #831607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831607 2023-08-20T11:14:42 Z Minindu206 분수 공원 (IOI21_parks) C++17
0 / 100
3 ms 5008 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
vector<int> adj[MAXN];
void dfs(int node, vector<int> &vis)
{
    vis[node] = 1;
    for(auto a:adj[node])
        if(!vis[node])
            dfs(a, vis);
}
int construct_roads(vector<int> x, vector<int> y)
{
    int n = x.size();
    map<pair<int, int>, int> ft;
    for(int i=0;i<n;i++)
    {
        ft[{x[i], y[i]}] = i;
    }
    vector<pair<int, int>> dir{{2, 0}, {-2, 0}, {0, 2}, {0, -2}};
    vector<int> u, v, a, b;
    for(int i=0;i<n;i++)
    {
        for(auto d:dir)
        {
            int cx = x[i] + d.first, cy = y[i] + d.second;
            if(!ft.count({cx, cy}))
                continue;
            ft[{cx, cy}];
            adj[i].push_back(ft[{cx, cy}]);
            if(ft[{cx, cy}] > i)
            {
                u.push_back(i);
                v.push_back(ft[{cx, cy}]);
                if(d.second == 0)
                {
                    a.push_back(x[i] + cx >> 1);
                    b.push_back(cy - 1);
                }
                else
                {
                    if(x[i] == 2)
                    {
                        a.push_back(x[i] - 1);
                        b.push_back(y[i] + cy >> 1); 
                    }
                    else
                    {
                        a.push_back(x[i] + 1);
                        b.push_back(y[i] + cy >> 1);
                    }
                }
            }
        }
    }
    vector<int> vis(n, 0);
    dfs(0, vis);
    for(int i=0;i<n;i++)
        if(!vis[i])
            return 0;
    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:38:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |                     a.push_back(x[i] + cx >> 1);
parks.cpp:46:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |                         b.push_back(y[i] + cy >> 1);
parks.cpp:51:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |                         b.push_back(y[i] + cy >> 1);
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5008 KB Output is correct
2 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5008 KB Output is correct
2 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5008 KB Output is correct
2 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5008 KB Output is correct
2 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5008 KB Output is correct
2 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5008 KB Output is correct
2 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
3 Halted 0 ms 0 KB -