結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,416 KB
testcase_01 AC 13 ms
4,352 KB
testcase_02 AC 30 ms
4,476 KB
testcase_03 AC 9 ms
4,356 KB
testcase_04 AC 23 ms
4,348 KB
testcase_05 AC 30 ms
4,348 KB
testcase_06 AC 24 ms
4,352 KB
testcase_07 AC 25 ms
4,352 KB
testcase_08 AC 18 ms
4,556 KB
testcase_09 AC 28 ms
4,352 KB
testcase_10 AC 32 ms
4,592 KB
testcase_11 AC 28 ms
4,352 KB
testcase_12 AC 20 ms
4,352 KB
testcase_13 AC 22 ms
4,352 KB
testcase_14 AC 20 ms
4,348 KB
testcase_15 AC 31 ms
4,352 KB
testcase_16 AC 26 ms
4,352 KB
testcase_17 AC 28 ms
4,352 KB
testcase_18 AC 29 ms
4,352 KB
testcase_19 AC 34 ms
4,844 KB
testcase_20 AC 0 ms
4,352 KB
testcase_21 AC 0 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 0 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘f3’ 内:
main.c:68:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   68 |         write(1,wp,wbuf+sizeof wbuf-wp);
      |         ^~~~~
main.c:69:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   69 |         _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
struct { int i,n; } ein[MAXV+1];
struct { int b,w; } ebw[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<ein[i].n;++k){
		int j=ebw[ein[i].i+k].b;
		int c=ebw[ein[i].i+k].w;
		if(c>=th) break;
		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; ++ein[t].i; }
		{ rd(t); uv[j<<1|1]=t; }
	}
	{
		int s=0;
		for(int i=0;++i<=n;){
			int t=s;
			s+=ein[i].i;
			ein[i].i=t;
		}
	}
	for(int j=0;j<q;++j){
		int i=uv[j<<1|0];
		int k=ein[i].i+ein[i].n++;
		ebw[k].b=uv[j<<1|1];
		ebw[k].w=j;
	}
	f3(f2(n,q));
}
0