結果
問題 | No.141 魔法少女コバ |
ユーザー |
![]() |
提出日時 | 2019-10-20 21:53:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 908 bytes |
コンパイル時間 | 1,760 ms |
コンパイル使用メモリ | 165,892 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 17:32:57 |
合計ジャッジ時間 | 3,577 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 93 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long long#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)#define itn int#define all(x) (x).begin(),(x).end()#define F first#define S secondconst long long INF = 1LL << 60;const int MOD = 1000000007;template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }int m,n;int res = 1145141919810;void solve(int m, int n, int ans){int prem=m, pren = n;if(n == m) chmin(res, ans);if(n<=0 || m<= 0) return ;int x = (m-1)/n;m -= n*x;ans += x;if(prem == m && pren == n) return ;solve(m, n, ans);solve(n, m, ans + 1);}signed main(void){cin>>m>>n;solve(m, n, 0);solve(n, m, 1);cout<<res<<endl;}