Submission #72525

# Submission time Handle Problem Language Result Execution time Memory
72525 2018-08-26T08:47:38 Z (#2175, xdoju, kazel, pps789) Key of Impassable Doors (FXCUP3_key) C++17
0 / 100
3 ms 740 KB
#include<bits/stdc++.h>
#include"key.h"
using namespace std;

int sz[1005], lft[1005];
int out[1005], mb[1005];
vector<int> cycle[1005];

bool is_cycle(int i, int N) {
  if(lft[sz[i]] < sz[i]) return false;
  vector<int> cand;
  for(int j=i+1;j<=N;j++) {
    if(sz[i] == sz[j] && !mb[j]) cand.push_back(j);
  }
  if(cand.size() == sz[i]-1) {
    cand.push_back(i);
    sort(cand.begin(), cand.end());
    int x = cand[0];
    for(int j : cand) {
      cycle[x].push_back(j);
      mb[j] = x;
    }
  } else {
    vector<int> rcand;
    random_shuffle(cand.begin(), cand.end());
    for(int k=0; k < cand.size(); k++) {
      int j = cand[k];
      TakeKey(i);
      TakeKey(j);
      int ret = Explore();
      if(ret == sz[i]) rcand.push_back(j);
      if(rcand.size() == sz[i]-1) break;
      if(rcand.size() + cand.size() - k < sz[i]) break;
    }
    if(rcand.size() < sz[i]-1) return false;
    rcand.push_back(i);
    sort(rcand.begin(), rcand.end());
    int x = rcand[0];
    for(int j : rcand) {
      cycle[x].push_back(j);
      mb[j] = x;
    }
  }
  return true;
}

bool is_tail(int i, int N) {
  vector<int> cand;
  if(sz[i] == 2 || lft[sz[i]-1]) {
    for(int j=1;j<=N;j++) {
      if(sz[j] == sz[i]-1) cand.push_back(j);
    }
    random_shuffle(cand.begin(), cand.end());
    for(int j : cand) {
      TakeKey(i);
      TakeKey(j);
      int ret = Explore();
      if(ret == sz[i]) {
        out[i] = j;
        return true;
      }
    }
  }
  return false;
}

mt19937 mt(random_device{}());

void EnsureKeyInfo(int N){
  for(int i=1;i<=N;i++) {
    TakeKey(i);
    sz[i] = Explore();
    if(sz[i] == 1) out[i] = i;
    else lft[sz[i]]++;
  }
  for(int i=1;i<=N;i++) {
    if(mb[i] || out[i]) continue;
    if(mt()&1) {
      if(is_tail(i,N)) {
        lft[sz[i]]--;
        continue;
      }
      is_cycle(i,N);
    } else {
      if(is_cycle(i,N)) {
        lft[sz[i]] -= sz[i];
        continue;
      }
      is_tail(i,N);
    }
  }
  for(int i=1;i<=N;i++) {
    if(mb[i]) {
      if(cycle[i].empty()) continue;
      for(int x : cycle[i]) {
        for(int y : cycle[i]) {
          Report(x,y);
        }
      }
    } else {
      int prv = i;
      Report(i,i);
      int x = out[i];
      while(x != prv) {
        if(mb[x]) {
          for(int j : cycle[mb[x]]) {
            Report(i, j);
          }
          break;
        } else {
          Report(i, x);
          prv = x;
          x = out[x];
        }
      }
    }
  }
}

Compilation message

key.cpp: In function 'bool is_cycle(int, int)':
key.cpp:15:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(cand.size() == sz[i]-1) {
      ~~~~~~~~~~~~^~~~~~~~~~
key.cpp:26:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k=0; k < cand.size(); k++) {
                  ~~^~~~~~~~~~~~~
key.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       if(rcand.size() == sz[i]-1) break;
          ~~~~~~~~~~~~~^~~~~~~~~~
key.cpp:33:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       if(rcand.size() + cand.size() - k < sz[i]) break;
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
key.cpp:35:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(rcand.size() < sz[i]-1) return false;
        ~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Runtime error 2 ms 740 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Runtime error 2 ms 740 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Runtime error 2 ms 740 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -