結果
| 問題 |
No.808 Kaiten Sushi?
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2019-03-23 03:15:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,290 bytes |
| コンパイル時間 | 1,193 ms |
| コンパイル使用メモリ | 128,872 KB |
| 最終ジャッジ日時 | 2025-01-07 00:08:23 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 WA * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:30: warning: ‘q’ may be used uninitialized [-Wmaybe-uninitialized]
48 | int m = -INF, m_ = INF, p, q;
| ^
main.cpp:96:38: warning: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
96 | t += (long long)(m - 1) * l + xy[p + 1].first;
| ~~^~~
main.cpp:48:27: note: ‘p’ was declared here
48 | int m = -INF, m_ = INF, p, q;
| ^
ソースコード
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007; // 998244353
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
cin.tie(0); ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n, l; cin >> n >> l;
vector<pair<int, bool> > xy; // true -> sushi
REP(i, n) {
int x; cin >> x;
xy.emplace_back(x, true);
}
REP(i, n) {
int y; cin >> y;
xy.emplace_back(y, false);
}
sort(ALL(xy));
vector<int> d(2 * n);
int m = -INF, m_ = INF, p, q;
REP(i, 2 * n) {
d[i] = (xy[i].second ? 1 : -1);
if (i > 0) d[i] += d[i - 1];
if (d[i] >= m) {
m = d[i];
p = i;
}
if (d[i] < m_) {
m_ = d[i];
q = i;
}
}
long long t = 0;
if (m_ < 0) {
int bye = -1;
REP(i, q) {
if (xy[i].second) {
bye = i;
break;
}
}
vector<pair<int, bool> > tmp(xy);
xy.clear();
FOR(i, q + 1, 2 * n) {
int umg = tmp[i].first - tmp[q + 1].first;
xy.emplace_back(umg, tmp[i].second);
}
REP(i, q) if (i != bye) {
int umg = l - tmp[q + 1].first + tmp[i].first;
xy.emplace_back(umg, tmp[i].second);
}
if (bye != -1) {
int umg = l - tmp[q + 1].first + tmp[q].first;
xy.emplace_back(umg, tmp[q].second);
n -= 2;
}
t += tmp[q + 1].first;
m = -INF;
REP(i, 2 * n) {
d[i] = (xy[i].second ? 1 : -1);
if (i > 0) d[i] += d[i - 1];
if (d[i] >= m) {
m = d[i];
p = i;
}
}
}
t += (long long)(m - 1) * l + xy[p + 1].first;
cout << t << '\n';
return 0;
}
emthrm