Submission #70486250


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;
int n,m,p[N],dp[N],l[N],r[N],mx[N],pm[N];
PII E[N];

void solve() {
	scanf("%d%d",&n,&m);
	rep(i,0,m) {
		int x,y;
		scanf("%d%d",&x,&y);
		E[i]=mp(x,y);
	}
	rep(i,1,n+1) scanf("%d",&p[i]);
	rep(i,0,n+2) l[i]=n+1,r[i]=0;
	l[0]=1; r[n+1]=n;
	rep(i,0,m) {
		auto [x,y]=E[i];
		x=p[x]; y=p[y];
		l[x]=min(l[x],y);
		r[y]=max(r[y],x);
	}
	rep(i,0,n+2) dp[i]=0,mx[i]=0,pm[i]=0;
	dp[0]=1;
	mx[1]=1;
	pm[0]=1;
	int mv=0;
	rep(i,1,n+2) {
		mv=max(mv,mx[i]);
		dp[i]=max(mv,pm[r[i]])+1;
		mx[l[i]]=max(mx[l[i]],dp[i]);
		pm[i]=max(pm[i-1],dp[i]);
	}
	printf("%d\n",(n+2)-dp[n+1]);
}
int _;
int main() {
	for (scanf("%d",&_);_;_--) {
		solve();
	}
	/*auto [num,mask]=build(10,10);
	for (auto x:num) printf("%d ",x);
	puts("");
	for (auto x:mask) {
		printf("%d %d\n",x,lis(num,x));
	}*/
}

Submission Info

Submission Time
Task A - Communicate Topological Order
User apiad
Language C++ 20 (gcc 12.2)
Score 700
Code Size 1559 Byte
Status AC
Exec Time 50 ms
Memory 10176 KiB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:32:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |                 scanf("%d%d",&x,&y);
      |                 ~~~~~^~~~~~~~~~~~~~
Main.cpp:35:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         rep(i,1,n+1) scanf("%d",&p[i]);
      |                      ~~~~~^~~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:59:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |         for (scanf("%d",&_);_;_--) {
      |              ~~~~~^~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 1
AC × 70
Set Name Test Cases
Sample sample.txt
All dense_1.txt, dense_10.txt, dense_2.txt, dense_3.txt, dense_4.txt, dense_5.txt, dense_6.txt, dense_7.txt, dense_8.txt, dense_9.txt, line_1.txt, line_10.txt, line_2.txt, line_3.txt, line_4.txt, line_5.txt, line_6.txt, line_7.txt, line_8.txt, line_9.txt, random_1.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_2.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_3.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_4.txt, random_40.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, sample.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt, small_5.txt, small_6.txt, small_7.txt, small_8.txt, small_9.txt
Case Name Status Exec Time Memory
dense_1.txt AC 37 ms 7128 KiB
dense_10.txt AC 37 ms 7544 KiB
dense_2.txt AC 38 ms 7908 KiB
dense_3.txt AC 38 ms 7052 KiB
dense_4.txt AC 38 ms 7632 KiB
dense_5.txt AC 39 ms 9812 KiB
dense_6.txt AC 37 ms 7036 KiB
dense_7.txt AC 39 ms 9260 KiB
dense_8.txt AC 39 ms 9276 KiB
dense_9.txt AC 37 ms 6968 KiB
line_1.txt AC 43 ms 5796 KiB
line_10.txt AC 45 ms 7756 KiB
line_2.txt AC 44 ms 7524 KiB
line_3.txt AC 42 ms 6712 KiB
line_4.txt AC 40 ms 6884 KiB
line_5.txt AC 42 ms 5596 KiB
line_6.txt AC 43 ms 6100 KiB
line_7.txt AC 42 ms 9204 KiB
line_8.txt AC 44 ms 6720 KiB
line_9.txt AC 43 ms 6416 KiB
random_1.txt AC 50 ms 10128 KiB
random_10.txt AC 27 ms 8768 KiB
random_11.txt AC 44 ms 7048 KiB
random_12.txt AC 50 ms 9960 KiB
random_13.txt AC 44 ms 7616 KiB
random_14.txt AC 39 ms 7992 KiB
random_15.txt AC 50 ms 9956 KiB
random_16.txt AC 43 ms 6984 KiB
random_17.txt AC 42 ms 7320 KiB
random_18.txt AC 41 ms 9640 KiB
random_19.txt AC 37 ms 7828 KiB
random_2.txt AC 50 ms 10092 KiB
random_20.txt AC 50 ms 10112 KiB
random_21.txt AC 49 ms 10112 KiB
random_22.txt AC 50 ms 10120 KiB
random_23.txt AC 48 ms 8916 KiB
random_24.txt AC 44 ms 9852 KiB
random_25.txt AC 48 ms 9524 KiB
random_26.txt AC 30 ms 8352 KiB
random_27.txt AC 44 ms 7432 KiB
random_28.txt AC 49 ms 10108 KiB
random_29.txt AC 50 ms 10176 KiB
random_3.txt AC 30 ms 8984 KiB
random_30.txt AC 41 ms 6972 KiB
random_31.txt AC 43 ms 7384 KiB
random_32.txt AC 45 ms 7652 KiB
random_33.txt AC 36 ms 7480 KiB
random_34.txt AC 49 ms 10096 KiB
random_35.txt AC 42 ms 6432 KiB
random_36.txt AC 44 ms 6844 KiB
random_37.txt AC 50 ms 10124 KiB
random_38.txt AC 32 ms 9028 KiB
random_39.txt AC 43 ms 6472 KiB
random_4.txt AC 43 ms 8864 KiB
random_40.txt AC 26 ms 8884 KiB
random_5.txt AC 44 ms 7176 KiB
random_6.txt AC 50 ms 9916 KiB
random_7.txt AC 49 ms 10124 KiB
random_8.txt AC 43 ms 6836 KiB
random_9.txt AC 44 ms 7712 KiB
sample.txt AC 1 ms 3876 KiB
small_1.txt AC 21 ms 3932 KiB
small_2.txt AC 21 ms 3736 KiB
small_3.txt AC 22 ms 3948 KiB
small_4.txt AC 21 ms 3736 KiB
small_5.txt AC 21 ms 3744 KiB
small_6.txt AC 22 ms 3932 KiB
small_7.txt AC 21 ms 3880 KiB
small_8.txt AC 22 ms 3952 KiB
small_9.txt AC 9 ms 3756 KiB