답안 #733695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733695 2023-05-01T08:11:44 Z tigar 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
1000 ms 1876480 KB
#include <bits/stdc++.h>
#include "supertrees.h"

using namespace std;

typedef long long ll;
vector<int> jedan[1010], dva[1010], nula[1010];
bitset<1010> jj[1010], sve[1010];
bool check[1010];
vector<int>lin;
vector<int>cc[1010];

bool provera(int x, std::vector<std::vector<int>>p, int cmp)
{
    lin.push_back(x);
    cc[cmp].push_back(x);
    int n=p.size();
    for(int i=0; i<jedan[x].size(); i++)
    {
        if(check[jedan[x][i]])continue;
        check[jedan[x][i]]=true;
        if(jj[x]!=jj[jedan[x][i]])return false;
    }
    for(int i=0; i<dva[x].size(); i++)
    {
        if(check[dva[x][i]])continue;
        check[dva[x][i]]=true;
        if(sve[x]!=sve[dva[x][i]])return false;
        if(!provera(dva[x][i], p, cmp))return false;
    }
    return true;
}

int construct(std::vector<std::vector<int>>p)
{
    int n=p.size();
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(p[i][j]==1)jedan[i].push_back(j);
            else if(p[i][j]==2)dva[i].push_back(j);
            else if(p[i][j]==3)return 0;
            if(p[i][j]==1){jj[i][j]=1; jj[j][i]=1; sve[j][i]=1; sve[i][j]=1;}
            else if(p[i][j]==2){sve[i][j]=1; sve[j][i]=1;}
            else if(p[i][j]==3)return 0;
        }
    }
    int br=1;
    for(int i=0; i<n; i++)
    {
        if(check[i])continue;
        if(!provera(i, p, br))return 0;
        br++;
    }
    vector<vector<int> > ans(n);
    for(int i=0; i<n; i++){ans[i].resize(n, 0);}
    for(int i=0; i<lin.size(); i++)
    {
        for(int j=1; j<jedan[lin[i]].size(); j++)
        {
            ans[jedan[lin[i]][j]][jedan[lin[i]][j-1]]=1;
            ans[jedan[lin[i]][j-1]][jedan[lin[i]][j]]=1;
        }
    }

    for(int i=1; i<br; i++)
    {
        for(int j=0; j<cc[i].size(); j++)
        {
            //cout<<cc[i][j]<<" ";
            if(cc[i].size()==2)return 0;
            ans[cc[i][j]][cc[i][(j+1)%cc[i].size()]]=1;
            ans[cc[i][(j+1)%cc[i].size()]][cc[i][j]]=1;
        }
        //cout<<endl;
    }
    for(int i=0; i<n; i++)
    {
        ans[i][i]=0;
    }
    //for(int i=0; i<n; i++){for(int j=0; j<n; j++)cout<<ans[i][j]<<" "; cout<<endl;}
    build(ans);
    return 1;
}

/*int main()
{
    int n; cin>>n;
    vector<vector<int> >p;
    for(int i=0; i<n; i++)
    {
        vector<int>pp(n);
        for(int j=0; j<n; j++)
        {
            cin>>pp[j];
        }
        p.push_back(pp);
    }
    cout<<construct(p);
}*/

Compilation message

supertrees.cpp: In function 'bool provera(int, std::vector<std::vector<int> >, int)':
supertrees.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0; i<jedan[x].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~
supertrees.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0; i<dva[x].size(); i++)
      |                  ~^~~~~~~~~~~~~~
supertrees.cpp:17:9: warning: unused variable 'n' [-Wunused-variable]
   17 |     int n=p.size();
      |         ^
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=0; i<lin.size(); i++)
      |                  ~^~~~~~~~~~~
supertrees.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int j=1; j<jedan[lin[i]].size(); j++)
      |                      ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int j=0; j<cc[i].size(); j++)
      |                      ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1468 KB Output is correct
7 Correct 179 ms 27796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1468 KB Output is correct
7 Correct 179 ms 27796 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 404 KB Output is correct
12 Correct 11 ms 1364 KB Output is correct
13 Correct 696 ms 24464 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 90 ms 16896 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 48 ms 6516 KB Output is correct
21 Correct 181 ms 24812 KB Output is correct
22 Correct 422 ms 24364 KB Output is correct
23 Correct 182 ms 26352 KB Output is correct
24 Correct 585 ms 24524 KB Output is correct
25 Correct 83 ms 14972 KB Output is correct
26 Correct 86 ms 14428 KB Output is correct
27 Correct 178 ms 27400 KB Output is correct
28 Correct 691 ms 24648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 12 ms 1364 KB Output is correct
9 Correct 668 ms 24680 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 26 ms 33952 KB Output is correct
13 Execution timed out 1127 ms 1876480 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 54 ms 6016 KB Output is correct
5 Correct 176 ms 22796 KB Output is correct
6 Correct 403 ms 22392 KB Output is correct
7 Correct 181 ms 24324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 162 ms 30432 KB Output is correct
10 Execution timed out 1115 ms 451760 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1468 KB Output is correct
7 Correct 179 ms 27796 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 404 KB Output is correct
12 Correct 11 ms 1364 KB Output is correct
13 Correct 696 ms 24464 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 90 ms 16896 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 48 ms 6516 KB Output is correct
21 Correct 181 ms 24812 KB Output is correct
22 Correct 422 ms 24364 KB Output is correct
23 Correct 182 ms 26352 KB Output is correct
24 Correct 585 ms 24524 KB Output is correct
25 Correct 83 ms 14972 KB Output is correct
26 Correct 86 ms 14428 KB Output is correct
27 Correct 178 ms 27400 KB Output is correct
28 Correct 691 ms 24648 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 12 ms 1364 KB Output is correct
37 Correct 668 ms 24680 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 26 ms 33952 KB Output is correct
41 Execution timed out 1127 ms 1876480 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1468 KB Output is correct
7 Correct 179 ms 27796 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 404 KB Output is correct
12 Correct 11 ms 1364 KB Output is correct
13 Correct 696 ms 24464 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 90 ms 16896 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 48 ms 6516 KB Output is correct
21 Correct 181 ms 24812 KB Output is correct
22 Correct 422 ms 24364 KB Output is correct
23 Correct 182 ms 26352 KB Output is correct
24 Correct 585 ms 24524 KB Output is correct
25 Correct 83 ms 14972 KB Output is correct
26 Correct 86 ms 14428 KB Output is correct
27 Correct 178 ms 27400 KB Output is correct
28 Correct 691 ms 24648 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 12 ms 1364 KB Output is correct
37 Correct 668 ms 24680 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 26 ms 33952 KB Output is correct
41 Execution timed out 1127 ms 1876480 KB Time limit exceeded
42 Halted 0 ms 0 KB -