Submission #1354134

#TimeUsernameProblemLanguageResultExecution timeMemory
1354134garam1732World Map (IOI25_worldmap)C++20
22 / 100
12 ms2264 KiB
#ifndef LOCAL
#include "worldmap.h"
#endif

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define bl ' '
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define comp(v) (v).erase(unique(all(v)), (v).end())
#define lbd(v,x) (lower_bound(all(v), (x))-(v).begin())
#define ubd(v,x) (upper_bound(all(v), (x))-(v).begin())
#define sz(v) ((int)(v).size())

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<int, pi> ipi;
typedef pair<pi, pi> pipi;
typedef pair<ll, ll> pll;

const int MAXN = 100100*5;
const ll MOD = 1e9+7;
const ll INF = 1e9+10;

vector<int> adj[44];
vector<int> v;
bool vst[44];

void dfs(int here) {
    v.push_back(here); vst[here]=1;
    for(int there:adj[here]) {
        if(vst[there]) continue;
        dfs(there); v.push_back(here);
    }
}

std::vector<std::vector<int>> create_map(int N, int M, std::vector<int> A, std::vector<int> B) {
    std::vector<std::vector<int>> ans(2 * N, std::vector<int>(2 * N, 0));
    for(int i=1;i<=N;i++) adj[i].clear(), vst[i]=0;
    for(int i=0;i<M;i++) {
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }

    v.clear(); dfs(1);
    vector<int> w = {};
    for(int i=1;i<=N;i++) {
        int mx=-1, idx;
        for(int j=0;j<sz(v);j++) {
            if(v[j]==i) {
                int tmp = min(j, sz(v)-1-j);
                if(mx < tmp) mx=tmp, idx=j;
            }
        }

        for(int j=0;j<=idx;j++) w.push_back(v[j]);
        w.push_back(i+N); w.push_back(i);
        for(int j=idx+1;j<sz(v);j++) w.push_back(v[j]);
        swap(v,w); w.clear();
    }

    assert(sz(v) == 4*N-1);
    for(int k=0;k<sz(v);k++) {
        int here=v[k];

        if(here <= N) {
            for(int i=0,j=k;i<2*N&&j>=0;i++,j--) {
                if(j>=2*N) continue;
                ans[i][j] = here;
            } continue;
        }

        here -= N;
        for(int i=0,j=k,t=0;i<2*N&&j>=0;i++,j--) {
            if(j>=2*N) continue;
            if(t<sz(adj[here])) ans[i][j] = adj[here][t++];
            else ans[i][j] = here;
        }
    }

    return ans;
}

#ifdef LOCAL
#include <cassert>
#include <cstdio>

int main() {
  int T;
  assert(1 == scanf("%d", &T));

  std::vector<int> Nt(T), Mt(T);
  std::vector<std::pair<std::vector<int>, std::vector<int>>> AB;

  for (int t = 0; t < T; ++t) {Nt[t]=21,Mt[t]=21*(21-1)/2;
    //assert(2 == scanf("%d %d", &Nt[t], &Mt[t]));

    int M = Mt[t];
    std::vector<int> A(M), B(M);

    int cnt=0;
    for(int i=1;i<=Nt[t];i++) for(int j=i+1;j<=Nt[t];j++) {
        A[cnt]=i; B[cnt]=j; cnt++;
    }
    // for (int i = 0; i < Mt[t]; i++) {
    //   //assert(2 == scanf("%d %d", &A[i], &B[i]));
    // }
    AB.push_back(make_pair(A, B));
  }

  fclose(stdin);

  std::vector<std::vector<std::vector<int>>> Ct;

  for (int t = 0; t < T; t++) {
    int N = Nt[t], M = Mt[t];
    std::vector<int> A = AB[t].first, B = AB[t].second;

    auto C = create_map(N, M, A, B);
    Ct.push_back(C);
  }

  for (int t = 0; t < T; t++) {
    auto& C = Ct[t];
    int P = (int)C.size();

    std::vector<int> Q(P);
    for (int i = 0; i < P; ++i)
      Q[i] = (int)C[i].size();

    printf("%d\n", P);
    for (int i = 0; i < P; ++i)
      printf("%d%c", Q[i], " \n"[i + 1 == P]);
    printf("\n");
    for (int i = 0; i < P; i++) {
      for (int j = 0; j < Q[i]; j++) {
        printf("%d%c", C[i][j], " \n"[j + 1 == Q[i]]);
      }
    }
    if (t < T - 1)
      printf("\n");
  }

  fclose(stdout);

  return 0;
}
#endif
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...