結果

問題 No.3008 某マヨネーズの網目柄
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-02-01 02:35:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,581 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 89,420 KB
実行使用メモリ 65,372 KB
最終ジャッジ日時 2023-09-05 08:48:40
合計ジャッジ時間 2,551 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 49 ms
65,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000009

vector<int> uf, usz;
int nc;

void init(int n){
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;

  for(int i = 0; i < uf.size(); i++){
    uf[i] = i;
  }
}

int find(int a){
  return (uf[a] == a) ? a : uf[a] = find(uf[a]);
}

void union_(int a, int b){
  a = find(a);
  b = find(b);

  if(a != b){
    if(usz[a] >= usz[b]){
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}

int check(int a, int b){
  return (find(a) == find(b)) ? 1 : 0;
}

int get_size(int a){
  return usz[find(a)];
}

int main(){
  int a,b;
  cin >> a >> b;
  int w = min(a,b);
  int h = max(a,b);
  init((w+h)*2);
  rep(i,0,h){
    if(0<=i-w){
      union_(i,h+i-w);
      union_(h+i,i-w);
    }
    if(i+w<h){
      union_(i,h+i+w);
      union_(h+i,i+w);
    }
  }
  rep(i,0,w){
    union_(h*2+i,i);
    union_(h*2+i,h+w-1-i);
    union_(h*2+w+i,w-1-i);
    union_(h*2+w+i,h+h+i-w);
  }
  cout << nc << endl;
  return 0;
}
0