結果

問題 No.799 赤黒かーどげぇむ
コンテスト
ユーザー GinFizz1185
提出日時 2019-07-06 07:53:12
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,269 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 220 ms
コンパイル使用メモリ 38,600 KB
最終ジャッジ日時 2026-02-22 03:46:28
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>
#include<stdlib.h>

#define STR_LENGTH 16
#define NUM_INPUT 4

void str_cut(char*, unsigned char*);

int main(void){
  unsigned char diff = 0;
  unsigned char same = 0;
  char str[STR_LENGTH];
  unsigned char input[NUM_INPUT] = {0};
  unsigned int ans = 0;

  fgets(str, sizeof(str), stdin);
  str_cut(str, input);

  if((input[3] < input[0]) || (input[1] < input[2])) {
    ans = (input[1] - input[0] + 1) * (input[3] - input[2] + 1);
  } else {
    diff = abs(input[2] - input[0]) + abs(input[3] - input[1]);
    same = ((input[1] - input[0] + 1) + (input[3] - input[2] + 1 - diff)) / 2;
    ans = (input[1] - input[0] + 1) * (input[3] - input[2] + 1) - same;
  }

  printf("%d\n", ans);
  return 0;
}

/*
関数概要:渡された文字列を空白で分離し、数値に変換する
第1引数:文字列
第2引数:文字列から数値に変換して格納する配列
*/
void str_cut(char* str, unsigned char* input){
  int start_str = 0;
  int num = 0; //配列NO
  int i = 0;

  while('\0' != str[i]){
    if(' ' == str[i]){
      str[i] = '\0';
      input[num] = (unsigned char) atoi(&str[start_str]);
      ++num;
      ++i;
      start_str = i;
    }
    ++i;
  }

  input[num] = (unsigned char) atoi(&str[start_str]);

  return;
}
0