結果
| 問題 |
No.3068 Speedrun (Hard)
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-03-23 18:31:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,516 ms / 2,000 ms |
| コード長 | 1,194 bytes |
| コンパイル時間 | 560 ms |
| コンパイル使用メモリ | 40,832 KB |
| 実行使用メモリ | 7,324 KB |
| 最終ジャッジ日時 | 2025-03-23 18:31:35 |
| 合計ジャッジ時間 | 10,583 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- 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;
}
tnakao0123