結果
| 問題 |
No.2157 崖
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-19 13:20:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,383 ms / 6,000 ms |
| コード長 | 1,609 bytes |
| コンパイル時間 | 931 ms |
| コンパイル使用メモリ | 87,812 KB |
| 最終ジャッジ日時 | 2025-02-11 15:21:13 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%d %d", &n, &m); gn=n; gm=m;
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:56:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | for (j=0; j<m; j++) scanf("%d", &as[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp: In function ‘char check(int)’:
main.cpp:32:37: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’ writing between 1 and 2147483647 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
32 | for (j=0; j<gm; j++) dp[gn-1][j]=1;
| ~~~~~~~~~~~^~
main.cpp:27:6: note: at offset [-3229815406592, -1504] into destination object ‘dp’ of size 2262016
27 | char dp[1504][1504];
| ^~
ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
bool operator()(const int& a, const int& b) {
return a<b;
}
};
int gn, gm;
char dp[1504][1504];
int as[1504][1504];
char check(int d) {
int i, j, s, e, c;
for (i=0; i<gn; i++) for (j=0; j<gm; j++) dp[i][j]=0;
for (j=0; j<gm; j++) dp[gn-1][j]=1;
for (i=gn-2; i>=0; i--) {
s=e=0; c=0;
for (j=0; j<gm; j++) {
dp[i][j]=0;
while(e<gm&&as[i+1][e]<=as[i][j]+d) {
c+=dp[i+1][e];
e++;
}
while(s<e&&as[i+1][s]<as[i][j]) {
c-=dp[i+1][s];
s++;
}
if (c) dp[i][j]=1;
}
}
for (j=0; j<gm; j++) if(dp[0][j]) return 1;
return 0;
}
int main() {
int n, i, mx, r, d, nr, j, m;
scanf("%d %d", &n, &m); gn=n; gm=m;
for (i=0; i<n; i++) {
for (j=0; j<m; j++) scanf("%d", &as[i][j]);
sort(as[i], as[i]+m);
}
mx = 1000000000;
if (check(mx)) {
r=mx; d=mx;
while(d) {
while(1) {
nr=r-d; if (nr<0) break;
if (check(nr)==0) break;
r=nr;
}
d>>=1;
}
printf("%d\n", r);
} else printf("-1\n");
return 0;
}