Submission #603560

#TimeUsernameProblemLanguageResultExecution timeMemory
603560Sam_a17Comparing Plants (IOI20_plants)C++14
Compilation error
0 ms0 KiB
// #include "A.cpp"
#include <bits/stdc++.h>
// #include <vector>
using namespace std;
 
#define sz(x) (int((x).size()))
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(x) cout << #x << " " << x << endl;
#define uniq(x) x.resize(unique(all(x)) - x.begin());
 
#define pb push_back
#define ld long double
#define ll long long
 
void build(std::vector<std::vector<int>> p);
 
const int N = 2e5 + 10, M = 1e3 + 10;
int par[N], sz[N];
set<int> st[N];
bitset<M> biti[M];
 
int find(int a) {
  if(a != par[a]) {
    par[a] = find(par[a]);
  }
  return par[a];
}
 
int same(int a, int b) {
  if(find(a) == find(b)) {
    return 1;
  } else {
    return 0;
  }
}
 
int merge(int a, int b) {
  a = find(a), b = find(b);
  if(a == b) {
    return 0;
  }
 
  if(sz[a] < sz[b]) {
    swap(a, b);
  }
 
  par[b] = a, sz[a] += sz[b];
  for(auto i: st[b]) {
    st[a].insert(i);
  } st[b].clear();
  return 1;
}
 
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	bool allOne = true, lowerOne = true, zeroOrtwo = true;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(p[i][j] != 1) {
        allOne = false;
      }
 
      if(p[i][j] > 1) {
        lowerOne = false;
      }
 
      if(i == j) continue;
      if(p[i][j] == 1 || p[i][j] == 3) {
        zeroOrtwo = false;
      }
    }
  }
 
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(p[i][j] != p[j][i]) {
        return 0;
      }
    }
  }
 
  if(allOne) {
    vector<vector<int>> answ(n, vector<int> (n, 0));
    for(int i = 0; i < n - 1; i++){
      answ[i][i + 1] = 1;
      answ[i + 1][i] = 1;
    }
	  build(answ);
    return 1;
  }
 
  if(lowerOne) {
    vector<vector<int>> answ(n, vector<int> (n, 0));
    
    for(int i = 0; i < n; i++) {
      par[i] = i, sz[i] = 1;
    }
    
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(p[i][j] == 1) {
          if(merge(i, j)) {
            answ[i][j] = answ[j][i] = 1;
          }
        }
      }
    }
 
 
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(same(i, j) != p[i][j]) {
          return 0;
        }
      }
    }
 
	  build(answ);
    return 1;
  }
 
  if(zeroOrtwo){
    vector<vector<int>> answ(n, vector<int> (n, 0));
    for(int i = 0; i < n; i++) {
      par[i] = i, sz[i] = 1;
      st[i].insert(i);
    }
    
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(p[i][j]) biti[i][j] = 1;
      }
    }
 
    // vector<int> out(n, 0);
    vector<int> ans, vis(n);
    vector<vector<int>> components;
    for(int i = 0; i < n; i++) {
      if(vis[i]) continue;
      // dbg(i)
 
      for(int j = 0; j < n; j++) {
        if(p[i][j] == 2) {
          // dbg(j) 
          merge(i, j);
        }
      }
 
      int pa = find(i);
 
      // const int x = n;
      bitset<M> bt;
 
      for(auto j: st[pa]) {
        bt[j] = 1;
      }
 
      // cout << bt << endl;
 
      for(auto j: st[pa]) {
        if((biti[j] | bt) != bt || (biti[j] & bt) != bt) {
          return 0;
        }
      }
 
      if(sz(st[pa]) == 2) {
        return 0;
      }
 
      vector<int> comp;
      for(auto j: st[pa]) {
        vis[j] = true;
        comp.push_back(j);
      }
 
      components.push_back(comp);
    }
 
    for(auto i: components) {
      for(int j = 1; j < sz(i); j++) {
        answ[i[j]][i[j - 1]] = 1;
        answ[i[j - 1]][i[j]] = 1;
      }
 
      answ[i.back()][i.front()] = 1;
      answ[i.front()][i.back()] = 1;
    }


    answ[4][4] = 0;
    // for(int i = 0; i < n; i++) {
    //   answ[i][i] = 1;
    // }

    build(answ);
    return 1;
  }
 
 
 
	return 1;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cck9rEbQ.o: in function `construct(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)':
plants.cpp:(.text+0xa27): undefined reference to `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
/usr/bin/ld: plants.cpp:(.text+0x12ea): undefined reference to `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
/usr/bin/ld: plants.cpp:(.text+0x15c9): undefined reference to `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
/usr/bin/ld: /tmp/ccFPJmBQ.o: in function `main':
grader.cpp:(.text.startup+0x2fb): undefined reference to `init(int, std::vector<int, std::allocator<int> >)'
/usr/bin/ld: grader.cpp:(.text.startup+0x347): undefined reference to `compare_plants(int, int)'
collect2: error: ld returned 1 exit status