結果

問題 No.2639 Longest Increasing Walk
ユーザー airthsairths
提出日時 2024-02-19 21:45:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,455 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 138,368 KB
実行使用メモリ 24,956 KB
最終ジャッジ日時 2024-09-29 01:40:04
合計ジャッジ時間 5,055 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 1 ms
6,820 KB
testcase_02 AC 1 ms
6,820 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 39 ms
17,200 KB
testcase_05 AC 61 ms
24,892 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 RE -
testcase_19 WA -
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
6,820 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 RE -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * 
 * 	^v^
 * 
 */
#include <iostream>
#include <numeric>
#include <set>
#include <iomanip>
#include <chrono>
#include <queue>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <bitset>
#include <algorithm>
#include <array>
#include <random>

using namespace std;

using ll = long long int;
using ld = long double;

#define iamtefu ios_base::sync_with_stdio(false); cin.tie(0);
#define fl(i,a,n) for (ll i{a}; i<n; i++)
#define fr(x,s) for(auto x:s)
#define rfl(i,a,n) for (ll i{n-1}; i>=a; i--)
#define ty int _; for(cin>>_; _--;)
#define print(a) for(auto ele:a){cout<<ele<<" ";}cout<<'\n';
#define all(x) x.begin(), x.end()

template <typename L, typename R>
inline bool chmax(L &a, R b){if (a<b){a=b;return 1;}return 0;}
template <typename L, typename R>
inline bool chmin(L &a, R b){if (a>b){a=b;return 1;}return 0;}

template <typename L, typename R>
ostream& operator<<(ostream &fout, const pair<L, R> &p){
	fout<<"{"<<p.first<<","<<p.second<<"}";
	return fout;
}

template <typename L, typename R, typename U>
ostream& operator<<(ostream &fout, const tuple<L, R, U> &p){
	auto &[l, r, u] = p;
	fout<<"{"<<l<<","<<r<<","<<u<<"}";
	return fout;
}

template <typename T>
ostream& operator<<(ostream &fout, const vector <T> &v){
	for (auto &x:v){
		fout<<x<<" ";
	}
	fout<<"\n";
	return fout;
}

template <typename T>
ostream& operator<<(ostream &fout, const set <T> &st){
	for (auto &x:st){
		fout<<x<<" ";
	}
	fout<<"\n";
	return fout;
}

template <typename T>
ostream& operator<<(ostream &fout, const multiset <T> &st){
	for (auto &x:st){
		fout<<x<<" ";
	}
	fout<<"\n";
	return fout;
}

template <typename K, typename V>
ostream& operator<<(ostream &fout, const map<K, V> &mp){
	fout<<"[";
	for (auto &[x,y]:mp){
		fout<<x<<":"<<y<<" ";
	}
	fout<<"]\n";
	return fout;
}

ll gcd(ll a, ll b){
	if (b==0){
		return a;
	}
	return gcd(b, a%b);
}

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll m){
	ll res=1;
	a%=m;
	while (b){
		if (b&1){
			res=(res*a)%m;
		}
		a=(a*a)%m;
		b/=2;
	}
	return res;
}

void scn(){
	// not necessarily distinct
	// right down
	
	ll n, m; cin>>n>>m;
	vector <vector <ll>> a(n, vector <ll>(m));
	fl(i,0,n){
		fl(j,0,m){
			cin>>a[i][j];
		}
	}
	vector <vector <ll>> ed((n*m)+1);
	fl(i,0,n){
		fl(j,0,m){
			if (j>0){
				if (a[i][j]>a[i][j-1]){
					ed[i*n+j-1].push_back(i*n+j);
				} else if (a[i][j]<a[i][j-1]){
					ed[i*n+j].push_back(i*n+j-1);
				}
			}
			if (i>0){
				if (a[i-1][j]>a[i][j]){
					ed[(i)*n+j].push_back((i-1)*n+j);
				} else if (a[i-1][j]<a[i][j]){
					ed[(i-1)*n+j].push_back(i*n+j);
				}
			}
		}
	}
	vector <ll> topo, vis(n*m+1);
	auto dfs=[&](const auto &self, ll i)->void{
		vis[i]++;
		for (auto x:ed[i]){
			if (!vis[x]){
				self(self, x);
			}
		}
		topo.push_back(i);
	};
	fl(i,0,n*m){
		if (!vis[i]){
			dfs(dfs, i);
		}
	}
	vector <ll> dp(n*m+1, 1);
	reverse(all(topo));
	for (auto x:topo){
		for (auto y:ed[x]){
			chmax(dp[y], dp[x]+1);
		}
	}
	cout<<*max_element(all(dp))<<'\n';
}

int main(){
	iamtefu;
#if defined(airths)
	auto t1=chrono::high_resolution_clock::now();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// ty
	{
		scn();
	}
#if defined(airths)
	auto t2=chrono::high_resolution_clock::now();
	ld ti=chrono::duration_cast<chrono::nanoseconds>(t2-t1).count();
	ti*=1e-6;
	cerr<<"Time: "<<setprecision(12)<<ti;
	cerr<<"ms\n";
#endif
	return 0;
}
0