제출 #556858

#제출 시각아이디문제언어결과실행 시간메모리
556858topovik슈퍼트리 잇기 (IOI20_supertrees)C++14
0 / 100
76 ms16460 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 = 1001; const int M = 500; vector <vector <int> > ans; vector <pair<int, int> > vc1; vector <int> vc3; pair<int, int> vc[N]; 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 hsh(vector <int> vc) { int sm = 0; for (int i = 0, p = 1; i < vc.size(); i++, p *= 3) sm += vc[i] * p; return sm; } int construct(std::vector<std::vector<int> > p) { int n = p.size(); n1 = n; if (n > M) assert(0); ans.resize(n); for (int i = 0; i < n; i++) ans[i].resize(n); for (int i = 0; i < n; i++) vc[i] = {hsh(p[i]), i}; sort(vc, vc + n); vc3.resize(n); for (int i = 1; i <= n; i++) if (i == n || vc[i].f != vc[i - 1].f) { for (int j = 0; j < n; j++) vc3[j] = (p[vc[i - 1].s][j] > 0); vc1.pb({hsh(vc3), vc[i - 1].s}); } else { ans[vc[i - 1].s][vc[i].s] = 1; ans[vc[i].s][vc[i - 1].s] = 1; } sort(vc1.begin(), vc1.end()); int ls = 0; for (int i = 1; i <= vc1.size(); i++) if (i == vc1.size() || 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; } for (int i = 0; i < n; i++) { Rec(i, 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 hsh(std::vector<int>)':
supertrees.cpp:105:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for (int i = 0, p = 1; i < vc.size(); i++, p *= 3) sm += vc[i] * p;
      |                            ~~^~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:136:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |     for (int i = 1; i <= vc1.size(); i++)
      |                     ~~^~~~~~~~~~~~~
supertrees.cpp:137:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |         if (i == vc1.size() || vc1[i].f != vc1[i - 1].f)
      |             ~~^~~~~~~~~~~~~
#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...