結果
| 問題 |
No.2999 Long Long Friedrice
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-12-30 16:30:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 851 bytes |
| コンパイル時間 | 552 ms |
| コンパイル使用メモリ | 55,484 KB |
| 最終ジャッジ日時 | 2025-02-26 17:15:11 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:34:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--;
| ~~~~~^~~~~~~~~~~~~~
main.cpp:35:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | for (int i = 0; i < n; i++) scanf("%d", bs + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2999.cc: No.2999 Long Long Friedrice - yukicoder
*/
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 2000;
const int MAX_M = 1000000;
/* typedef */
using vi = vector<int>;
/* global variables */
int as[MAX_N], bs[MAX_N];
vi nbrs[MAX_M];
bool ds[MAX_M];
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--;
for (int i = 0; i < n; i++) scanf("%d", bs + i);
int m = 0;
for (int i = 0; i < n; i++) {
nbrs[as[i]].push_back(as[i] + bs[i]);
m = max(m, as[i] + bs[i]);
}
ds[0] = true;
int maxu = 0;
for (int u = 0; u <= m; u++)
if (ds[u]) {
maxu = u;
for (auto v: nbrs[u]) ds[v] = true;
}
printf("%d\n", maxu + 1);
return 0;
}
tnakao0123