結果

問題 No.1021 Children in Classrooms
ユーザー tailstails
提出日時 2020-11-12 15:08:25
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,643 bytes
コンパイル時間 1,404 ms
コンパイル使用メモリ 32,596 KB
実行使用メモリ 5,160 KB
最終ジャッジ日時 2023-09-30 01:14:25
合計ジャッジ時間 3,581 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 5 ms
5,132 KB
testcase_10 AC 5 ms
5,160 KB
testcase_11 AC 5 ms
5,068 KB
testcase_12 AC 5 ms
4,992 KB
testcase_13 AC 4 ms
5,100 KB
testcase_14 AC 4 ms
4,996 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,824 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘putrange’ 内:
main.c:62:9: 警告: 関数 ‘memcpy’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   62 |         memcpy(wp,a[st],len);
      |         ^~~~~~
main.c:1:1: 備考: include ‘<string.h>’ or provide a declaration of ‘memcpy’
  +++ |+#include <string.h>
    1 | #pragma GCC optimize("Ofast")
main.c:62:9: 警告: 組み込み関数 ‘memcpy’ の互換性がない暗黙的な宣言です [-Wbuiltin-declaration-mismatch]
   62 |         memcpy(wp,a[st],len);
      |         ^~~~~~
main.c:62:9: 備考: include ‘<string.h>’ or provide a declaration of ‘memcpy’
main.c: トップレベル:
main.c:66:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   66 | main(){
      | ^~~~
main.c: 関数 ‘main’ 内:
main.c:109:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
  109 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:110:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
  110 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

char*mmap();
#define RD(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}

char wbuf[7*200000+100];

char* putzeros(char*wp,int n){
	while(n>0){
		*(long*)wp=0x2030203020302030l;
		wp+=8;
		n-=4;
	}
	return wp+(n+n);
}

char* putint(char*wp,int v){
	if(v>=100000000){
		{
			int v1=v/100000000;
			int n=0;
			int a=0;
			while(a=a<<8|v1%10|0x30,++n,v1/=10);
			*(int*)wp=a;
			wp+=n;
		}
		{
			int n=8;
			long a=0;
			while(a=a<<8|v%10|0x30,v/=10,--n);
			*(long*)wp=a;
			wp+=8;
		}
	}else{
		int n=0;
		long a=0;
		while(a=a<<8|v%10|0x30,++n,v/=10);
		*(long*)wp=a;
		wp+=n;
	}
	*wp++=0x20;
	return wp;
}

char* a[200001];

char* putsum(char*wp,int st,int en){
	char*rp=a[st];
	int s=0;
	for(en-=st;en--;){
		int v=0;
		int c;
		while(c=*rp++-48,c>=0)v=v*10+c;
		s+=v;
	}
	return putint(wp,s);
}

char* putrange(char*wp,int st,int en){
	int len=a[en]-a[st];
	memcpy(wp,a[st],len);
	return wp+len;
}

main(){
	char*rp=mmap(0l,7l*2+6l*200000+200001+2,1,2,0,0ll);
	RD(n);
	while(*rp++!=10);
	for(int i=0;i<n;++i){
		a[i]=rp;
		while(*rp++>=48);
	}
	a[n]=rp;
	char*wp=wbuf;
	int x=0,x0=0,x1=0;
	int c;
	while(c=*rp++,c!=10){
		if(c=='L'){
			if(x1<++x) x1=x;
		}else{
			if(x0>--x) x0=x;
		}
		if(x1-x0==n-1){
			goto l1;
		}
	}
	wp=putzeros(wp,x1-x);
	wp=putsum(wp,0,x1+1);
	wp=putrange(wp,x1+1,n+x0-1);
	wp=putsum(wp,n+x0-1,n);
	wp=putzeros(wp,x-x0);
	goto l2;

	l1:;
	x=x1-x;
	while(c=*rp++,c!=10){
		if(c=='L'){
			if(--x<0) x=0;
		}else{
			if(++x>n-1) x=n-1;
		}
	}
	wp=putzeros(wp,x);
	wp=putsum(wp,0,n);
	wp=putzeros(wp,n-x-1);

	l2:
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0