結果

問題 No.3068 Speedrun (Hard)
ユーザー tnakao0123
提出日時 2025-03-23 18:29:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,194 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 40,832 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-23 18:29:16
合計ジャッジ時間 12,885 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   scanf("%d%d%d%d%d%d%d%d%d%d", &a, &b, &c, &d, &n, &p, &q, &r, &s, &t);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3068.cc:  No.3068 Speedrun (Hard) - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* subroutines */

// x+y=u,rx+sy=v
// |1 1|*|x|=|u| -> |s s|*|x|=|su| -> (s-r)x=(su-v) -> x=(su-v)/(s-r)
// |r s| |y| |v|    |r s| |y| | v|
// -> |r r|*|x|=|ru| -> (r-s)y=ru-v -> y=-(ru-v)/(s-r)
//    |r s| |y| | v|

void calc(int c, int d, int r, int s, int u, int v, int &x, int &y) {
  x = y = -1;

  if (r == s) {
    if (c + d <= u && r * u == v) x = min(c, u), y = u - x;
    return;
  }

  int x0 = s * u - v, y0 = r * u - v, sr = s - r;
  if (x0 % sr == 0 && y0 % sr == 0) x = x0 / sr, y = -y0 / sr;
  if (x < 0 || x > c || y < 0 || y > d) x = y = -1;
}

/* main */

int main() {
  int a, b, c, d, n, p, q, r, s, t;
  scanf("%d%d%d%d%d%d%d%d%d%d", &a, &b, &c, &d, &n, &p, &q, &r, &s, &t);


  for (int i = 0; i <= a && i <= n && p * i <= t; i++)
    for (int j = 0; j <= b && i + j <= n && p * i + q * j <= t; j++) {
      int u = n - (i + j);
      int v = t - (p * i + q * j);
      int x, y;
      calc(c, d, r, s, u, v, x, y);
      if (x >= 0) {
	printf("%d %d %d %d\n", i, j, x, y);
	return 0;
      }
    }

  puts("-1");
  return 0;
}
0