提出 #64828019


ソースコード 拡げる

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

const int N = 1e3;
const int M = 2e5;
struct edge {
  int v, w, next;
} edg[M];
int n, m, h[N], lev[N], cur[N];
int cnt = -1;
int dfs(int u, int canflow) {
  if(u == n + m + 2) return canflow;
  int resflow = 0;
  for(int& i = cur[u]; ~i; i = edg[i].next) {
    int v = edg[i].v;
    if(lev[v] == lev[u] + 1 && edg[i].w > 0) {
      int nowflow = dfs(v, min(canflow, edg[i].w));
      canflow -= nowflow;
      resflow += nowflow;
      edg[i].w -= nowflow;
      edg[i ^ 1].w += nowflow;
      if(!canflow) break;
    }
  }
  if(!resflow) lev[u] = -1;
  return resflow;
}
bool bfs() {
  memset(lev, -1, sizeof lev);
  queue<int> que;
  lev[n + m + 1] = 0;
  que.push(n + m + 1);
  while(!que.empty()) {
    int u = que.front(); que.pop();
    for(int i = h[u]; ~i; i = edg[i].next) {
      int v = edg[i].v;
      if(lev[v] == -1 && edg[i].w > 0) {
        lev[v] = lev[u] + 1;
        que.push(v);
      }
    }
  }
  return ~lev[n + m + 2];
}

int dinic() {
  int maxflow = 0;
  while(bfs()) {
    for(int i = 1; i <= n + m + 2; i++)
      cur[i] = h[i];
    maxflow += dfs(n + m + 1, INT_MAX);
  }
  return maxflow;
}

void add_edge(int u, int v) {
  edg[++cnt] = (edge){v, 1, h[u]}; h[u] = cnt;
  edg[++cnt] = (edge){u, 0, h[v]}; h[v] = cnt;
}

void init(int n_) {
  n = m = n_;
  cnt = -1;
  memset(h, -1, sizeof(h));
}

} // namesapce Dinic

const int N = 305;
typedef long long ll;
typedef __int128 lll;

int n;
ll sx[N], sy[N], gx[N], gy[N];

lll dist2(int i, int j) {
  return (lll)(sx[i] - gx[j]) * (sx[i] - gx[j]) + 
    (lll)(sy[i] - gy[j]) * (sy[i] - gy[j]);
}

bool check(lll r2) {
  Dinic::init(n);
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
      if(dist2(i, j) <= r2) {
        // 人 1 ~ n,         i
        // 按钮 n+1 ~ 2n     n+j
        // 源点 2n+1
        // 汇点 2n+2
        Dinic::add_edge(i, n + j);
      }
    }
  }
  for(int i = 1; i <= n; i++) {
    Dinic::add_edge(n + n + 1, i);
    Dinic::add_edge(n + i, n + n + 2);
  }
  return Dinic::dinic() == n;
}

int main() {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%lld %lld", &sx[i], &sy[i]);
  }
  for(int i = 1; i <= n; i++) {
    scanf("%lld %lld", &gx[i], &gy[i]);
  }
  // 二分 r^2 的值
  lll lb = 1, rb = 2 * (lll)1e18 * (lll)1e18;
  while(lb < rb) {
    lll mid = (lb + rb) / 2;
    if(check(mid)) rb = mid;
    else lb = mid + 1;
  }
  printf("%.10Lf\n", sqrtl((long double)rb));
  return 0;
}

提出情報

提出日時
問題 G - Push Simultaneously
ユーザ syksykCCC
言語 C++ 20 (gcc 12.2)
得点 575
コード長 2619 Byte
結果 AC
実行時間 965 ms
メモリ 6000 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:103:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  103 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
Main.cpp:105:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  105 |     scanf("%lld %lld", &sx[i], &sy[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:108:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  108 |     scanf("%lld %lld", &gx[i], &gy[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 575 / 575
結果
AC × 3
AC × 42
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 02_handmade_32.txt, 02_handmade_33.txt, 02_handmade_34.txt, 02_handmade_35.txt, 02_handmade_36.txt, 02_handmade_37.txt, 02_handmade_38.txt, 02_handmade_39.txt, 02_handmade_40.txt, 02_handmade_41.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3768 KiB
00_sample_01.txt AC 1 ms 3724 KiB
00_sample_02.txt AC 1 ms 3812 KiB
01_random_03.txt AC 136 ms 5720 KiB
01_random_04.txt AC 644 ms 5900 KiB
01_random_05.txt AC 603 ms 5888 KiB
01_random_06.txt AC 632 ms 5928 KiB
01_random_07.txt AC 643 ms 5720 KiB
01_random_08.txt AC 562 ms 5860 KiB
01_random_09.txt AC 314 ms 5804 KiB
01_random_10.txt AC 203 ms 5884 KiB
01_random_11.txt AC 213 ms 5932 KiB
01_random_12.txt AC 888 ms 5748 KiB
01_random_13.txt AC 965 ms 5948 KiB
01_random_14.txt AC 717 ms 5944 KiB
01_random_15.txt AC 655 ms 5856 KiB
01_random_16.txt AC 306 ms 5788 KiB
01_random_17.txt AC 202 ms 5876 KiB
01_random_18.txt AC 258 ms 5816 KiB
01_random_19.txt AC 248 ms 5908 KiB
01_random_20.txt AC 91 ms 6000 KiB
01_random_21.txt AC 89 ms 5756 KiB
01_random_22.txt AC 91 ms 5776 KiB
01_random_23.txt AC 244 ms 5984 KiB
01_random_24.txt AC 95 ms 5776 KiB
01_random_25.txt AC 88 ms 5764 KiB
01_random_26.txt AC 89 ms 5968 KiB
01_random_27.txt AC 594 ms 5568 KiB
01_random_28.txt AC 473 ms 5636 KiB
01_random_29.txt AC 256 ms 5848 KiB
01_random_30.txt AC 263 ms 5896 KiB
01_random_31.txt AC 258 ms 5724 KiB
02_handmade_32.txt AC 360 ms 5936 KiB
02_handmade_33.txt AC 273 ms 5936 KiB
02_handmade_34.txt AC 734 ms 5748 KiB
02_handmade_35.txt AC 302 ms 5872 KiB
02_handmade_36.txt AC 333 ms 5848 KiB
02_handmade_37.txt AC 273 ms 5748 KiB
02_handmade_38.txt AC 314 ms 5760 KiB
02_handmade_39.txt AC 313 ms 5852 KiB
02_handmade_40.txt AC 337 ms 5724 KiB
02_handmade_41.txt AC 273 ms 5844 KiB