結果

問題 No.2900 Star Divine
ユーザー hos.lyrichos.lyric
提出日時 2024-09-20 22:30:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 2,803 bytes
コンパイル時間 1,280 ms
コンパイル使用メモリ 122,512 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-20 22:30:28
合計ジャッジ時間 2,666 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 32 ms
6,940 KB
testcase_02 AC 33 ms
6,940 KB
testcase_03 AC 35 ms
6,940 KB
testcase_04 AC 35 ms
6,944 KB
testcase_05 AC 35 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 35 ms
6,944 KB
testcase_08 AC 22 ms
6,940 KB
testcase_09 AC 23 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


#include <chrono>
#ifdef LOCAL
mt19937_64 rng(58);
#else
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif


int N0, N1, M;
vector<pair<int, int>> P;

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d%d", &N0, &N1, &M);
    P.resize(M);
    for (int i = 0; i < M; ++i) {
      scanf("%d%d", &P[i].first, &P[i].second);
      --P[i].first;
      --P[i].second;
    }
    sort(P.begin(), P.end());
    P.erase(unique(P.begin(), P.end()), P.end());
    M = P.size();
    
    for (; ; ) {
      vector<int> on0(N0, 0), on1(N1, 0);
      // if (N0 <= N1) {
        // fill(on1.begin(), on1.end(), 1);
      // } else {
        for (int v = 0; v < N1; ++v) on1[v] = rng() & 1;
        for (int i = 0; i < M; ++i) if (on1[P[i].second]) on0[P[i].first] ^= 1;
      // }
      int cnt[2] = {};
      for (int u = 0; u < N0; ++u) cnt[0] += on0[u];
      for (int v = 0; v < N1; ++v) cnt[1] += on1[v];
      if (cnt[0] + cnt[1] >= (N0 + N1 + 1) / 2) {
        printf("%d %d\n", cnt[0], cnt[1]);
        {
          int ou = 0;
          for (int u = 0; u < N0; ++u) if (on0[u]) {
            if (ou++) printf(" ");
            printf("%d", u + 1);
          }
          puts("");
        }
        {
          int ou = 0;
          for (int v = 0; v < N1; ++v) if (on1[v]) {
            if (ou++) printf(" ");
            printf("%d", v + 1);
          }
          puts("");
        }
        break;
      }
    }
    
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}
0