AtCoder Regular Contest 004

Submission #1051574

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

ll lcm (ll x, ll y) {
  return x / __gcd(x, y) * y;
}

struct Ratio {
  ll num;
  ll den;
  Ratio() {}
  Ratio(ll n, ll d) {
    num = n;
    den = d;
    reduce();
  }
  void reduce() {
    ll g = __gcd(num, den);
    num /= g;
    den /= g;
  }
  Ratio operator - () const { return Ratio(-num, den); }
  Ratio &operator += (const Ratio &r){
    ll l = lcm(den, r.den);
    num *= (l / den);
    num += (l / r.den * r.num);
    den = l;
    reduce();
    return *this;
  }
  Ratio operator + (const Ratio &r) {
    return Ratio(*this) += r;
  }
  Ratio &operator -= (const Ratio &r){
    return *this += (-r);
  }
  Ratio operator - (const Ratio &r) {
    return Ratio(*this) -= r;
  }
};

int main() {
  ll x, y;
  scanf("%lld/%lld", &x, &y);
  ll g = __gcd(x, y);
  x /= g;
  y /= g;
  ll orig = (ll)floor((double)x * 2.0 / y);

  Ratio xy(x, y);
  vvll ans;
  rep (i, 2) {
    ll N = orig + i;
    if (N == 0) {
      continue;
    }
    Ratio mn = Ratio(1+N, 2) - xy;
    if (N % mn.den != 0) {
      continue;
    }
    ans.push_back({N, N / mn.den * mn.num});
  }

  if (ans.empty()) {
    printf("Impossible\n");
    return 0;
  }

  for (auto elm : ans) {
    printf("%lld %lld\n", elm[0], elm[1]);
  }

  return 0;
}

Submission

Task問題 C - 平均値太郎の憂鬱 ( The melancholy of Taro Heikinchi )
User nameユーザ名 mu
Created time投稿日時
Language言語 C++11 (GCC 4.8.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 2195 Byte
File nameファイル名
Exec time実行時間 28 ms
Memory usageメモリ使用量 928 KB

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:78:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld/%lld", &x, &y);
^

Test case

Set

Set name Score得点 / Max score Cases
All 100 / 100 00_killer.txt,00_max.txt,00_min.txt,00_min2.txt,00_sample_01.txt,00_sample_02.txt,00_sample_03.txt,00_sample_04.txt,01_rnd_00.txt,01_rnd_01.txt,01_rnd_02.txt,01_rnd_03.txt,01_rnd_04.txt,01_rnd_05.txt,01_rnd_06.txt,01_rnd_07.txt,01_rnd_08.txt,01_rnd_09.txt,01_rnd_10.txt,01_rnd_11.txt,01_rnd_12.txt,01_rnd_13.txt,01_rnd_14.txt,01_rnd_15.txt,01_rnd_16.txt,01_rnd_17.txt,01_rnd_18.txt,01_rnd_19.txt,02_rnd2_00.txt,02_rnd2_01.txt,02_rnd2_02.txt,02_rnd2_03.txt,02_rnd2_04.txt,02_rnd2_05.txt,02_rnd2_06.txt,02_rnd2_07.txt,02_rnd2_08.txt,02_rnd2_09.txt,02_rnd2_10.txt,02_rnd2_11.txt,02_rnd2_12.txt,02_rnd2_13.txt,02_rnd2_14.txt,02_rnd2_15.txt,02_rnd2_16.txt,02_rnd2_17.txt,02_rnd2_18.txt,02_rnd2_19.txt,03_smallrnd_00.txt,03_smallrnd_01.txt,03_smallrnd_02.txt,03_smallrnd_03.txt,03_smallrnd_04.txt,03_smallrnd_05.txt,03_smallrnd_06.txt,03_smallrnd_07.txt,03_smallrnd_08.txt,03_smallrnd_09.txt,04_primes_01.txt,04_primes_02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_killer.txt AC 18 ms 924 KB
00_max.txt AC 19 ms 924 KB
00_min.txt AC 17 ms 800 KB
00_min2.txt AC 18 ms 800 KB
00_sample_01.txt AC 17 ms 796 KB
00_sample_02.txt AC 19 ms 924 KB
00_sample_03.txt AC 19 ms 796 KB
00_sample_04.txt AC 19 ms 796 KB
01_rnd_00.txt AC 19 ms 800 KB
01_rnd_01.txt AC 18 ms 800 KB
01_rnd_02.txt AC 17 ms 792 KB
01_rnd_03.txt AC 17 ms 800 KB
01_rnd_04.txt AC 19 ms 800 KB
01_rnd_05.txt AC 19 ms 800 KB
01_rnd_06.txt AC 18 ms 800 KB
01_rnd_07.txt AC 18 ms 800 KB
01_rnd_08.txt AC 17 ms 800 KB
01_rnd_09.txt AC 19 ms 792 KB
01_rnd_10.txt AC 18 ms 800 KB
01_rnd_11.txt AC 19 ms 800 KB
01_rnd_12.txt AC 17 ms 800 KB
01_rnd_13.txt AC 17 ms 800 KB
01_rnd_14.txt AC 17 ms 844 KB
01_rnd_15.txt AC 17 ms 800 KB
01_rnd_16.txt AC 19 ms 796 KB
01_rnd_17.txt AC 17 ms 800 KB
01_rnd_18.txt AC 17 ms 800 KB
01_rnd_19.txt AC 17 ms 872 KB
02_rnd2_00.txt AC 18 ms 928 KB
02_rnd2_01.txt AC 18 ms 796 KB
02_rnd2_02.txt AC 19 ms 800 KB
02_rnd2_03.txt AC 19 ms 796 KB
02_rnd2_04.txt AC 18 ms 788 KB
02_rnd2_05.txt AC 18 ms 800 KB
02_rnd2_06.txt AC 17 ms 800 KB
02_rnd2_07.txt AC 19 ms 796 KB
02_rnd2_08.txt AC 19 ms 860 KB
02_rnd2_09.txt AC 19 ms 800 KB
02_rnd2_10.txt AC 19 ms 796 KB
02_rnd2_11.txt AC 19 ms 800 KB
02_rnd2_12.txt AC 17 ms 796 KB
02_rnd2_13.txt AC 19 ms 792 KB
02_rnd2_14.txt AC 28 ms 800 KB
02_rnd2_15.txt AC 19 ms 844 KB
02_rnd2_16.txt AC 18 ms 792 KB
02_rnd2_17.txt AC 19 ms 800 KB
02_rnd2_18.txt AC 19 ms 800 KB
02_rnd2_19.txt AC 18 ms 800 KB
03_smallrnd_00.txt AC 18 ms 872 KB
03_smallrnd_01.txt AC 17 ms 792 KB
03_smallrnd_02.txt AC 18 ms 924 KB
03_smallrnd_03.txt AC 17 ms 924 KB
03_smallrnd_04.txt AC 19 ms 800 KB
03_smallrnd_05.txt AC 19 ms 796 KB
03_smallrnd_06.txt AC 17 ms 800 KB
03_smallrnd_07.txt AC 17 ms 924 KB
03_smallrnd_08.txt AC 19 ms 796 KB
03_smallrnd_09.txt AC 17 ms 800 KB
04_primes_01.txt AC 19 ms 928 KB
04_primes_02.txt AC 19 ms 800 KB