結果

問題 No.1865 Make Cycle
ユーザー tailstails
提出日時 2022-03-09 18:28:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 36 ms / 3,000 ms
コード長 1,461 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 31,704 KB
実行使用メモリ 4,916 KB
最終ジャッジ日時 2023-10-11 19:34:39
合計ジャッジ時間 3,435 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,356 KB
testcase_01 AC 15 ms
4,352 KB
testcase_02 AC 32 ms
4,488 KB
testcase_03 AC 12 ms
4,348 KB
testcase_04 AC 27 ms
4,352 KB
testcase_05 AC 32 ms
4,348 KB
testcase_06 AC 25 ms
4,352 KB
testcase_07 AC 27 ms
4,352 KB
testcase_08 AC 19 ms
4,696 KB
testcase_09 AC 30 ms
4,352 KB
testcase_10 AC 34 ms
4,604 KB
testcase_11 AC 30 ms
4,352 KB
testcase_12 AC 22 ms
4,348 KB
testcase_13 AC 24 ms
4,456 KB
testcase_14 AC 21 ms
4,352 KB
testcase_15 AC 33 ms
4,352 KB
testcase_16 AC 28 ms
4,356 KB
testcase_17 AC 30 ms
4,352 KB
testcase_18 AC 31 ms
4,348 KB
testcase_19 AC 36 ms
4,916 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 0 ms
4,352 KB
testcase_23 AC 0 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘f3’ 内:
main.c:71:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   71 |         write(1,wp,wbuf+sizeof wbuf-wp);
      |         ^~~~~
main.c:72:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   72 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd(v) long v=0;{long _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define wt(v) {ulong _z=v;do*--wp=_z%10+48;while(_z/=10);}
#define rep(v,e) for(long v=0;v<e;++v)

typedef unsigned long ulong;

#define MAXV 100000
#define MAXE 100000
int en[MAXV+1];
int ei[MAXV+1];
int eb[MAXE];
int ew[MAXE];
int uv[MAXE<<1];

char vis[MAXV+1];
int th;

#define mada    0
#define atta    1
#define nakatta 2

int f(int i){
	if(vis[i]!=mada) return vis[i];
	vis[i]=atta;
	for(int k=0;k<en[i];++k){
		int j=eb[ei[i]+k];
		int c=ew[ei[i]+k];
		if(c<th){
			int r=f(j);
			if(r==atta){
				return r;
			}
		}
	}
	return vis[i]=nakatta;
}

long f2(long n,long q){
	long lo=-1;
	long hi=q+1;
	while(lo+1<hi){
		th=lo+hi>>1;
		rep(i,n){
			vis[i+1]=mada;
		}
		rep(i,n){
			if(!vis[i+1]){
				if(f(i+1)==atta){
					hi=th;
					goto next;
				}
			}
		}
		lo=th;
		next:;
	}
	return hi>q?-1:hi;
}

void f3(long z){
	char wbuf[64],*wp=wbuf+sizeof wbuf;
	if(z<0){
		*--wp='1';
		*--wp='-';
	}else{
		wt(z);
	}
	write(1,wp,wbuf+sizeof wbuf-wp);
	_exit(0);

}

int main(){
	char*mmap();
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd(n);
	rd(q);
	for(int j=0;j<q;++j){
		{ rd(t); uv[j<<1|0]=t; ++ei[t]; }
		{ rd(t); uv[j<<1|1]=t; }
	}
	{
		int s=0;
		for(int i=0;++i<=n;){
			int t=s;
			s+=ei[i];
			ei[i]=t;
		}
	}
	for(int j=0;j<q;++j){
		int i=uv[j<<1|0];
		int k=ei[i]+en[i]++;
		eb[k]=uv[j<<1|1];
		ew[k]=j;
	}
	f3(f2(n,q));
}
0