제출 #556853

#제출 시각아이디문제언어결과실행 시간메모리
556853topovik슈퍼트리 잇기 (IOI20_supertrees)C++14
0 / 100
1082 ms37764 KiB
#include <bits/stdc++.h> #include <vector> #include <cassert> #include <cstdio> #include <cstdlib> #include <string> #include "supertrees.h" #define pb push_back #define f first #define s second using namespace std; // //static int n; //static std::vector<std::vector<int>> p; //static std::vector<std::vector<int>> b; //static bool called = false; // //int construct(std::vector<std::vector<int>>); // //static void _assert(bool cond, const char* error) { // if (!cond) { // printf("%s\n", error); // exit(0); // } //} // //void build(std::vector<std::vector<int>> _b) { // _assert(!called, "build is called more than once"); // called = true; // _assert((int) _b.size() == n, "Invalid number of rows in b"); // for (int i = 0; i < n; i++) // _assert((int) _b[i].size() == n, "Invalid number of columns in b"); // b = _b; //} // //int main() { // assert(scanf("%d", &n) == 1); // // p.resize(n); // for (int i = 0; i < n; i++) // p[i].resize(n); // // for (int i = 0; i < n; i++) // for (int j = 0; j < n; j++) // assert(scanf("%d", &p[i][j]) == 1); // fclose(stdin); // // int possible = construct(p); // // _assert(possible == 0 || possible == 1, "Invalid return value of construct"); // if (possible == 1) // _assert(called, "construct returned 1 without calling build"); // else // _assert(!called, "construct called build but returned 0"); // // printf("%d\n", possible); // if (possible == 1) // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // if (j) // printf(" "); // printf("%d", b[i][j]); // } // printf("\n"); // } //} const int N = 1501; vector <vector <int> > ans; int mrk[N]; int kol[N][N]; int n1; void Rec(int st, int x) { kol[st][x]++; mrk[x] = 1; for (int i = 0; i < n1; i++) if (!mrk[i] && ans[x][i]) Rec(st, i); mrk[x] = 0; } int construct(std::vector<std::vector<int> > p) { int n = p.size(); n1 = n; ans.resize(n); for (int i = 0; i < n; i++) ans[i].resize(n); vector <pair<vector<int>, int> > vc; for (int i = 0; i < n; i++) vc.pb({p[i], i}); sort(vc.begin(), vc.end()); vector <pair<vector<int>, int> > vc1; vector <int> vc3; for (int i = 1; i < n; i++) if (vc[i].f != vc[i - 1].f) { vc3.clear(); for (int j = 0; j < n; j++) vc3.pb(vc[i - 1].f[j] > 0); vc1.pb({vc3, vc[i - 1].s}); } else { ans[vc[i - 1].s][vc[i].s] = 1; ans[vc[i].s][vc[i - 1].s] = 1; } vc3.clear(); for (int j = 0; j < n; j++) vc3.pb(vc[n - 1].f[j] > 0); vc1.pb({vc3, vc[n - 1].s}); sort(vc1.begin(), vc1.end()); int ls = 0; for (int i = 1; i < vc1.size(); i++) if (vc1[i].f != vc1[i - 1].f) { if (ls != i - 1) { ans[vc1[i - 1].s][vc1[ls].s] = 1; ans[vc1[ls].s][vc1[i - 1].s] = 1; if (p[vc1[ls].s][vc1[i - 1].s] == 3) { if (i - ls >= 4) { ans[vc1[i - 1].s][vc1[ls + 1].s] = 1; ans[vc1[ls + 1].s][vc1[i - 1].s] = 1; } else return 0; } } ls = i; } else { ans[vc1[i].s][vc1[i - 1].s] = 1; ans[vc1[i - 1].s][vc1[i].s] = 1; } int m = vc1.size(); if (ls != m - 1) { ans[vc1[m - 1].s][vc1[ls].s] = 1; ans[vc1[ls].s][vc1[m - 1].s] = 1; if (p[vc1[ls].s][vc1[m - 1].s] == 3) { if (m - ls >= 4) { ans[vc1[m - 1].s][vc1[ls + 1].s] = 1; ans[vc1[ls + 1].s][vc1[m - 1].s] = 1; } else return 0; } } for (int i = 0; i < n; i++) Rec(i, i); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (kol[i][j] != p[i][j]) return 0; build(ans); return 1; } /* 4 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 1 */

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:143:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |     for (int i = 1; i < vc1.size(); i++)
      |                     ~~^~~~~~~~~~~~
#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...