結果

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

テストケース

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

ソースコード

diff #

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

const int maxs = 100;
int c=1,g[1000][maxs*2+1],s[1000],p[1000],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]){
					del(i,v);
					return;
				}
			}
		}
	}
}

void add(int x, int y)
{
	for (int i=0;i<c;i++) if (s[i]){
		int u = g[i][0] + p[i];
		int v = g[i][s[i]-1] + p[i];
		if (x <= u && v <= y) p[i]++;
		else if (max(x,u) <= min(v,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