AtCoder Typical Contest 001

Submission #1177718

Source codeソースコード

#pragma GCC target ("arch=sandybridge")

#include <unistd.h>
#include <string.h>
#include <stdlib.h>

char ibuf[3000018];
char *ibufe = ibuf-1;

void readall(){
  int k, t = 0;
  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;
  if(t>=sizeof(ibuf)) exit(0);
}

int read_uint(){
  int x=0;
  while(*(++ibufe) <'0');
  do {
    x *= 10;
    x += *ibufe-'0';
  } while(*(++ibufe) >='0');

  return x;
}

char buf[800001];
char *bufe = buf;

void write_yesno(int b){
  if(b){
    *bufe++ = 'Y';
    *bufe++ = 'e';
    *bufe++ = 's';
  }
  else {
    *bufe++ = 'N';
    *bufe++ = 'o';
  }
  *bufe++ = '\n';
}

void flush(){
  write(STDOUT_FILENO, buf, bufe-buf);
}

int tree[100000];

int root(int i){
  if(tree[i]<0) return i;
  return tree[i] = root(tree[i]);
}

void unite(int i, int j){
  int ri = root(i);
  int rj = root(j);
  if(ri == rj) return;
  if(tree[ri] == tree[rj]){
    tree[rj] = ri;
    tree[ri]--;
  }
  else if(tree[ri] < tree[rj])
    tree[rj] = ri;
  else
    tree[ri] = rj;
}

int main(){
  int q, i;
  memset(tree, -1, sizeof(tree));
  readall();
  read_uint();
  q = read_uint();
  for(i=0;i<q;i++){
    int p = read_uint();
    int a = read_uint();
    int b = read_uint();
    if(p)
      write_yesno(root(a) == root(b));
    else
      unite(a, b);
  }

  flush();
  return 0;
}

Submission

Task問題 B - Union Find
User nameユーザ名 ryuhei
Created time投稿日時
Language言語 C (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1404 Byte
File nameファイル名
Exec time実行時間 6 ms
Memory usageメモリ使用量 4992 KB

Compiler messageコンパイルメッセージ

./Main.c: In function ‘flush’:
./Main.c:44:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
write(STDOUT_FILENO, buf, bufe-buf);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_sample_01.txt
All 100 / 100 00_sample_01.txt,subtask_01_01.txt,subtask_01_02.txt,subtask_01_03.txt,subtask_01_04.txt,subtask_01_05.txt,subtask_01_06.txt,subtask_01_07.txt,subtask_01_08.txt,subtask_01_09.txt,subtask_01_10.txt,subtask_01_11.txt,subtask_01_12.txt,subtask_01_13.txt,subtask_01_14.txt,subtask_01_15.txt,subtask_01_16.txt,subtask_01_17.txt,subtask_01_18.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01.txt AC 1 ms 512 KB
subtask_01_01.txt AC 4 ms 4224 KB
subtask_01_02.txt AC 1 ms 512 KB
subtask_01_03.txt AC 4 ms 4992 KB
subtask_01_04.txt AC 6 ms 4608 KB
subtask_01_05.txt AC 1 ms 768 KB
subtask_01_06.txt AC 1 ms 768 KB
subtask_01_07.txt AC 6 ms 4608 KB
subtask_01_08.txt AC 6 ms 4608 KB
subtask_01_09.txt AC 1 ms 512 KB
subtask_01_10.txt AC 1 ms 512 KB
subtask_01_11.txt AC 4 ms 4736 KB
subtask_01_12.txt AC 6 ms 4608 KB
subtask_01_13.txt AC 5 ms 4352 KB
subtask_01_14.txt AC 1 ms 512 KB
subtask_01_15.txt AC 4 ms 4608 KB
subtask_01_16.txt AC 6 ms 4608 KB
subtask_01_17.txt AC 6 ms 4096 KB
subtask_01_18.txt AC 6 ms 4096 KB