Submission #758156

# Submission time Handle Problem Language Result Execution time Memory
758156 2023-06-14T08:23:15 Z Sam_a17 Chameleon's Love (JOI20_chameleon) C++17
44 / 100
48 ms 516 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
// #include "chameleon.h"
// #include <atcoder/all>
#include <cstdio>
using namespace std;
 
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif
 
#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 clr(x) (x).clear()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define blt(x) __builtin_popcount(x)

#define pb push_back
#define popf pop_front
#define popb pop_back
#define ld long double
#define ll long long
 
void print(long long t) {cerr << t;}
void print(int t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
void print(double t) {cerr << t;}
void print(unsigned long long t) {cerr << t;}
void print(long double t) {cerr << t;}
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define nl '\n'

// Indexed Set
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T> void print(T v[],T n) {cerr << "["; for(int i = 0; i < n; i++) {cerr << v[i] << " ";} cerr << "]";}
template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(Tree <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(deque <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
 
// for random generations
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 myrand(131);
 
// for grid problems
int dx[8] = {-1,0,1,0,1,-1,1,-1};
int dy[8] = {0,1,0,-1,1,1,-1,-1};
 
long long ka() {
	long long x = 0;
	bool z = false;
	while (1)
	{
		char y = getchar();
		if (y == '-')
			z = true;
		else if ('0' <= y && y <= '9')
			x = x * 10 + y - '0';
		else
		{
			if (z)
				x *= -1;
			return x;
		}
	}
}
 
// lowest / (1 << 17) >= 1e5 / (1 << 18) >= 2e5 / (1 << 21) >= 1e6
void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
}
// file in/out
void setIO(string str = "") {
  fastIO();
 
  if (str != "") {
    freopen((str + ".in").c_str(), "r", stdin);
    freopen((str + ".out").c_str(), "w", stdout);
  } else if(str == "input") {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
}

const int maxN = 1005;
bool vis[maxN];
vector<int> bro[maxN], adj[maxN];
int n, p[maxN], iran[maxN];

int Query(const std::vector<int> &p);
void Answer(int a, int b);

vector<int> first, second;
bool vis2[maxN];

vector<int> g[5];

void Solve(int N) {
  n = N;

  g[0].push_back(1);
  for(int i = 2; i <= 2 * n; i++) {
    bool added = false;
    for(int j = 0; j <= 3; j++) {
      g[j].push_back(i);
      int qry = sz(g[j]) - Query(g[j]);
      if(qry) {
        g[j].pop_back();

        int lst = -1;
        while(true) {
          if(lst != -1) {
            vector<int> vi{i};
            for(int k = lst + 1; k <= sz(g[j]) - 1; k++) {
              vi.push_back(g[j][k]);
            }

            if(Query(vi) == sz(vi)) {
              break;
            }
          }

          int ina = lst + 1, inb = sz(g[j]) - 1, ans = -1;
          while(ina <= inb) {
            int mid = (ina + inb) / 2;
            vector<int> toask{i};
            for(int k = lst + 1; k <= mid; k++) {
              toask.push_back(g[j][k]);
            }

            if(Query(toask) != sz(toask)) {
              ans = mid;
              inb = mid - 1;
            } else {
              ina = mid + 1;
            }
          }

          if(ans == -1) break;
          bro[g[j][ans]].push_back(i);
          bro[i].push_back(g[j][ans]);
          lst = ans;
        }
      } else {
        if(added) {
          g[j].pop_back();
        }
        added = true;
      }
    }
  }


  for(int i = 1; i <= 2 * n; i++) {
    vector<int> which = bro[i];
    if(sz(which) == 3) {
      bro[i] = which;
      for(int j = 0; j < (1 << 3); j++) {
        if(blt(j) != 2) continue;

        vector<int> ask{i};
        int to = -1;
        for(int k = 0; k < 3; k++) {
          if(j & (1 << k)) {
            ask.push_back(which[k]);
          } else {
            to = which[k];
          }
        }

        if(Query(ask) == 1) {
          p[i] = to;
          iran[to] = i;
          break;
        }
      }
    }
  }

  for(int i = 1; i <= 2 * n; i++) {
    if(vis[i]) continue;
    if(bro[i].empty()) continue;

    int harazat = -1;
    for(auto j: bro[i]) {
      if(j == p[i]) continue;
      if(j == iran[i]) continue;
      assert(harazat == -1);
      harazat = j;
    }
    assert(harazat != -1);

    vis[i] = vis[harazat] = true;
    Answer(i, harazat);
  }

  // special case
  vector<int> toask;
  for(int i = 1; i <= 2 * n; i++) {
    if(vis[i]) continue;
    toask.push_back(i);

    if(sz(toask) >= 2) {
      int ss = Query(toask);
      if(ss == sz(toask) - 1) {
        int ina = 0, inb = sz(toask) - 2, ans = -1;
        while(ina <= inb) {
          int mid = (ina + inb) / 2;
          vector<int> newask{i};

          for(int j = 0; j <= mid; j++) {
            newask.push_back(toask[j]);
          }

          if(Query(newask) == sz(newask) - 1) {
            ans = mid;
            inb = mid - 1;
          } else {
            ina = mid + 1;
          }
        }

        assert(ans != -1);

        vis[toask[ans]] = true;
        vis[i] = true;


        Answer(toask[ans], i);

        vector<int> newask;
        for(auto j: toask) {
          if(vis[j]) continue;
          newask.push_back(j);
        }
        toask.swap(newask);
      }
    }
  }


}

Compilation message

chameleon.cpp: In function 'void setIO(std::string)':
chameleon.cpp:94:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |     freopen((str + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:95:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     freopen((str + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:97:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:98:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 28 ms 396 KB Output is correct
4 Correct 29 ms 396 KB Output is correct
5 Correct 26 ms 336 KB Output is correct
6 Correct 27 ms 392 KB Output is correct
7 Correct 26 ms 412 KB Output is correct
8 Correct 28 ms 416 KB Output is correct
9 Correct 30 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 380 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Incorrect 48 ms 384 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 28 ms 396 KB Output is correct
4 Correct 29 ms 396 KB Output is correct
5 Correct 26 ms 336 KB Output is correct
6 Correct 27 ms 392 KB Output is correct
7 Correct 26 ms 412 KB Output is correct
8 Correct 28 ms 416 KB Output is correct
9 Correct 30 ms 516 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 380 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Incorrect 48 ms 384 KB Wrong Answer [3]
31 Halted 0 ms 0 KB -