結果

問題 No.686 Uncertain LIS
ユーザー kriiikriii
提出日時 2018-12-08 23:35:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,511 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 43,576 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-12 16:33:14
合計ジャッジ時間 5,641 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 140 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 69 ms
4,348 KB
testcase_12 AC 3 ms
4,352 KB
testcase_13 AC 28 ms
4,348 KB
testcase_14 AC 31 ms
4,352 KB
testcase_15 AC 21 ms
4,348 KB
testcase_16 AC 54 ms
4,348 KB
testcase_17 WA -
testcase_18 AC 178 ms
4,348 KB
testcase_19 AC 177 ms
4,348 KB
testcase_20 AC 70 ms
4,348 KB
testcase_21 AC 70 ms
4,348 KB
testcase_22 AC 22 ms
4,348 KB
testcase_23 AC 22 ms
4,352 KB
testcase_24 AC 50 ms
4,352 KB
testcase_25 AC 50 ms
4,348 KB
testcase_26 AC 428 ms
4,352 KB
testcase_27 AC 51 ms
4,348 KB
testcase_28 AC 51 ms
4,352 KB
testcase_29 AC 52 ms
4,348 KB
testcase_30 AC 51 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 539 ms
4,352 KB
testcase_33 AC 438 ms
4,352 KB
testcase_34 AC 178 ms
4,352 KB
testcase_35 AC 176 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
using namespace std;

const int maxs = 100;
int c=1,g[1010][maxs*2+1],s[1010],p[1010],r[100010];

void del(int i, int v)
{
	s[i]--;
	for (int j=v;j<s[i];j++) g[i][j] = g[i][j+1];
}

void rem(int y)
{
	for (int i=0;i<c;i++) if (s[i]){
		if (y <= g[i][s[i]-1] + p[i]){
			for (int v=0;v<s[i];v++){
				if (y <= g[i][v] + p[i]){
					del(i,v);
					return;
				}
			}
		}
	}
}

void add(int x, int y)
{
	for (int i=0;i<c;i++) if (s[i]){
		int a = g[i][0] + p[i];
		int b = g[i][s[i]-1] + p[i];
		if (x <= a && b <= y) p[i]++;
		else if (max(x,a) <= min(b,y)){
			for (int v=0;v<s[i];v++){
				int &a = g[i][v];
				a += p[i];
				if (x <= a && a <= y) a++;
			}
			p[i] = 0;
		}
	}
}

void mak(int i, int v)
{
	for (int j=s[i];j>v;j--) g[i][j] = g[i][j-1];
	s[i]++;
}

void just()
{
	int n = 0;
	for (int i=0;i<c;i++){
		for (int j=0;j<s[i];j++){
			r[n++] = g[i][j] + p[i];
		}
	}

	c = (n + maxs - 1) / maxs;
	for (int i=0;i<c;i++) s[i] = p[i] = 0;
	for (int i=0;i<n;i++){
		g[i/maxs][i%maxs] = r[i];
		s[i/maxs]++;
	}
}

void ins(int x)
{
	for (int i=0;i<c;i++){
		if (!s[i] || x <= g[i][s[i]-1] + p[i] || i == c-1){
			int v = 0;
			while (v < s[i] && x > g[i][v] + p[i]) v++;
			mak(i,v);
			g[i][v] = x - p[i];
			if (s[i] == maxs*2) just();
			break;
		}
	}
}

int main()
{
	int N; scanf ("%d",&N); while (N--){
		int x,y; scanf ("%d %d",&x,&y);
		rem(y);
		add(x,y);
		ins(x);
	}

	int ans = 0;
	for (int i=0;i<c;i++) ans += s[i];
	printf ("%d\n",ans);

	return 0;
}
0