結果

問題 No.1198 お菓子配り-1
ユーザー tnakao0123tnakao0123
提出日時 2020-08-30 18:47:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,379 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 96,196 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 08:04:29
合計ジャッジ時間 1,748 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1198.cc:  No.1198 お菓子配り-1 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_L = 25;

/* typedef */

typedef long long ll;
typedef vector<int> vi;

/* global variables */

char s[MAX_L + 4];

/* subroutines */

inline void normalizev(vi &a) {
  while (! a.empty() && a.back() == 0) a.pop_back();
}

inline void setv(vi &a, char s[]) {
  int n = strlen(s);
  a.resize(n);
  for (int i = n - 1; i >= 0; i--) a[n - 1 - i] = s[i] - '0';
  normalizev(a);
}

int divv(vi &c, const vi &a, const int b) { // c = a / b (return a % b)
  int an = a.size();
  ll co = 0;
  c.assign(an, 0);

  for (int i = an - 1; i >= 0; i--) {
    ll d = co * 10 + a[i];
    c[i] = d / b;
    co = d - c[i] * b;
  }
  normalizev(c);
  return (int)co;
}

/* main */

int main() {
  scanf("%s", s);

  vi a, b;
  setv(a, s);

  int c2 = 0;
  while (! (a[0] & 1)) {
    c2++;
    divv(b, a, 2);
    swap(a, b);
  }

  printf("%d\n",
	 (c2 == 1 || (c2 <= 2 && a.size() == 1 && a[0] == 1)) ? -1 : 1);
  //printf("c2=%d\n", c2);
  return 0;
}
0