結果
| 問題 |
No.2157 崖
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2022-12-06 00:20:35 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,626 bytes |
| コンパイル時間 | 3,100 ms |
| コンパイル使用メモリ | 164,916 KB |
| 実行使用メモリ | 35,340 KB |
| 最終ジャッジ日時 | 2024-10-14 14:37:54 |
| 合計ジャッジ時間 | 27,964 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 22 |
コンパイルメッセージ
main.cpp:1:17: warning: using directive refers to implicitly-defined namespace 'std'
1 | using namespace std;
| ^
1 warning generated.
ソースコード
using namespace std;
#include "bits/stdc++.h"
#define REP(a, b) for (long long a = 0; a < b; ++a)
#define ALL(a) begin(a), end(a)
#define ld long double
#define int long long
vector<vector<int>> inputs;
int n, m;
int can(int target)
{
vector<vector<int>> nexts(n, vector<int>(m, 0));
REP(i, m)
{
nexts[0][i] = 1;
}
for (int i = 1; i < n; ++i)
{
int l = 0;
int r = 0;
int cnts = 0;
for (int j = 0; j < m; ++j)
{
while (r != m and inputs[i - 1][r] <= inputs[i][j])
{
cnts += nexts[i - 1][r];
r++;
}
while (l != m and inputs[i - 1][l] + target + 1 <= inputs[i][j])
{
cnts -= nexts[i - 1][l];
l++;
}
if (cnts != 0)
{
nexts[i][j] = 1;
}
}
}
REP(i, m)
{
if (nexts[n - 1][i])
return 1;
}
return 0;
}
void solve()
{
cin >> n >> m;
REP(i, n)
{
vector<int> now;
REP(q, m)
{
int x;
cin >> x;
now.push_back(x);
}
sort(ALL(now));
inputs.push_back(now);
}
int bot = 1e18;
int top = 0;
while (bot - top > 1)
{
int mid = (bot + top) / 2;
if (can(mid))
{
bot = mid;
}
else
{
top = mid;
}
}
if (can(bot))
{
cout << bot << endl;
}
else
{
cout << -1 << endl;
}
}
#undef int
int main()
{
// Fasterize input/output script
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(100);
int t = 1;
// cin >> t; // comment out if solving multi testcase
for (int testCase = 1; testCase <= t; ++testCase)
{
solve();
}
return 0;
}
kotamanegi