結果

問題 No.141 魔法少女コバ
ユーザー IJMP320
提出日時 2015-02-02 00:09:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 53,092 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-23 05:49:11
合計ジャッジ時間 6,460 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 92
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |         scanf("%d %d",&N,&M);
      |         ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
const int INF = 100000000;

int gcd( int m, int n ) {
	if((0==m)||(0==n)) return 0;
	while( m != n )	{
		if (m>n) m = m - n;
		else n = n - m;
	}
	return m;
}

struct K{
	int n;
	int m;
	int deep;
	K():n(0),m(0), deep(0){}
	K(int n,int m, int deep) {
		this->n = n;
		this->m = m;
		this->deep = deep;
	}
};

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

	int ret = gcd(N,M);
	N /= ret;
	M /= ret;

	queue<K> q;
	q.push(K(1,1,0));
	while(q.size()!=0) {
		K k = q.front(); q.pop();
		if(k.n == N && k.m == M) {
			printf("%d\n",k.deep);
			return 0;
		}
		K nk1=k, nk2=k;
		nk1.n += k.m;
		nk1.deep++;
		nk2.n = k.m;
		nk2.m = k.n;
		nk2.deep++;
		if(nk1.n > N && nk1.m > M) q.push(nk1);
		if(nk2.n > N && nk2.m > M) q.push(nk2);
	}

	return 0;
}
0