Submission #317178

#TimeUsernameProblemLanguageResultExecution timeMemory
317178amunduzbaevConnecting Supertrees (IOI20_supertrees)C++14
21 / 100
467 ms25336 KiB
//#include "grader.cpp" #include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int N=1005; int used[N]; int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int> > b(n); bool ok1=0, ok2=0, ok0=0; for(int i=0;i<n;i++){ b[i].resize(n); for(int j=0;j<n;j++){ b[i][j]=0; if(p[i][j] == 1) ok1=1; else if(p[i][j] == 2) ok2=1; else ok0 = 1; } } if(ok1 && !ok2 && !ok0){ for(int i=1;i<n;i++){ b[0][i] = 1; b[i][0] = 1; } build(b); return 1; } else if(ok1 || ok0 && !ok2){ vector<vector<int>> v(n); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(p[i][j] == 1 && i!=j){ v[i].push_back(j); } } for(int j=0;j<v[i].size();j++){ if(!p[v[i][j]][i]) return 0; for(int l=j;l<v[i].size();l++){ if(!p[v[i][l]][v[i][j]]) return 0; } } } for(int i=0;i<n;i++){ if(used[i]) continue; for(int j=0;j<v[i].size();j++){ used[v[i][j]] = 1; b[i][v[i][j]] = 1; b[v[i][j]][i] = 1; } } build(b); return 1; } else if(ok2 || ok0&&!ok1){ vector<vector<int>> v(n); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(p[i][j] == 2 && i!=j){ v[i].push_back(j); } } for(int j=0;j<v[i].size();j++){ if(!p[v[i][j]][i]) return 0; for(int l=j+1;l<v[i].size();l++){ if(!p[v[i][l]][v[i][j]]) return 0; } } } for(int i=0;i<n;i++){ if(used[i]) continue; b[i][v[i][0]] = 1; b[v[i][0]][i] = 1; int sz=v[i].size(); for(int j=0;j<sz-1;j++){ used[v[i][j]] = 1; b[v[i][j]][v[i][j+1]] = 1; b[v[i][j+1]][v[i][j]] = 1; } b[i][v[i][sz-1]] = 1; b[v[i][sz-1]][i] = 1; } build(b); return 1; } return 0; } /* 4 1 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 4 1 1 1 0 1 1 1 0 1 1 1 0 0 0 0 1 4 0 2 2 2 2 0 2 2 2 2 0 2 2 2 2 0 */

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:30:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   30 |  else if(ok1 || ok0 && !ok2){
      |                 ~~~~^~~~~~~
supertrees.cpp:38:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for(int j=0;j<v[i].size();j++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int l=j;l<v[i].size();l++){
      |                 ~^~~~~~~~~~~~
supertrees.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    for(int j=0;j<v[i].size();j++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:56:20: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   56 |  else if(ok2 || ok0&&!ok1){
      |                 ~~~^~~~~~
supertrees.cpp:64:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int j=0;j<v[i].size();j++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:66:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int l=j+1;l<v[i].size();l++){
      |                   ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...