結果

問題 No.152 貯金箱の消失
コンテスト
ユーザー koyumeishi
提出日時 2015-02-16 20:23:38
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 907 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,953 ms
コンパイル使用メモリ 167,636 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:01:29
合計ジャッジ時間 1,985 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |         scanf("%d", &L);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

#define MOD 1000003


// n / d
struct Rational{
	int n;
	int d;
	Rational(int n_, int d_) : n(n_), d(d_){
	}

	Rational operator+(const Rational &x) const{
		return Rational(this->n + x.n, this->d + x.d);
	}
};



int main(){
	int L;
	scanf("%d", &L);

	function<int(const Rational&, const Rational&)> Stern_Brocot_Tree = [&](const Rational &low, const Rational &high) -> int{
		Rational med = low+high;

		int n = med.n;
		int m = med.d;
		if( 8LL*m*(n+m) > L ) return 0;

		int ret = (m&1) ^ (n&1);
		ret += Stern_Brocot_Tree(low, med);
		ret += Stern_Brocot_Tree(med, high);

		return ret;
	};

	int ans = Stern_Brocot_Tree(Rational(0,1), Rational(1,1));

	ans %= MOD;
	printf("%d\n", ans);

	return 0;
}
0