結果

問題 No.1703 Much Matching
ユーザー publflpublfl
提出日時 2021-10-08 22:52:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 312 ms / 2,000 ms
コード長 1,130 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 56,096 KB
実行使用メモリ 20,500 KB
最終ジャッジ日時 2023-09-30 12:03:34
合計ジャッジ時間 4,100 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,160 KB
testcase_01 AC 3 ms
9,168 KB
testcase_02 AC 2 ms
9,224 KB
testcase_03 AC 3 ms
9,168 KB
testcase_04 AC 2 ms
9,160 KB
testcase_05 AC 3 ms
9,224 KB
testcase_06 AC 83 ms
14,332 KB
testcase_07 AC 7 ms
9,180 KB
testcase_08 AC 90 ms
14,392 KB
testcase_09 AC 107 ms
14,492 KB
testcase_10 AC 15 ms
9,348 KB
testcase_11 AC 23 ms
11,444 KB
testcase_12 AC 6 ms
9,200 KB
testcase_13 AC 42 ms
13,740 KB
testcase_14 AC 4 ms
9,136 KB
testcase_15 AC 20 ms
11,392 KB
testcase_16 AC 55 ms
13,920 KB
testcase_17 AC 66 ms
14,016 KB
testcase_18 AC 3 ms
9,196 KB
testcase_19 AC 138 ms
17,016 KB
testcase_20 AC 17 ms
11,424 KB
testcase_21 AC 165 ms
17,340 KB
testcase_22 AC 63 ms
14,060 KB
testcase_23 AC 50 ms
13,796 KB
testcase_24 AC 4 ms
9,144 KB
testcase_25 AC 8 ms
9,196 KB
testcase_26 AC 32 ms
13,624 KB
testcase_27 AC 71 ms
14,076 KB
testcase_28 AC 135 ms
16,892 KB
testcase_29 AC 26 ms
13,508 KB
testcase_30 AC 38 ms
13,708 KB
testcase_31 AC 5 ms
9,156 KB
testcase_32 AC 70 ms
14,096 KB
testcase_33 AC 47 ms
13,828 KB
testcase_34 AC 6 ms
9,176 KB
testcase_35 AC 14 ms
9,332 KB
testcase_36 AC 312 ms
20,500 KB
testcase_37 AC 3 ms
9,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>

int C = 1;
std::pair<int,int> P[1000010];

int check[1000010];
int next[1000010],prev[1000010];
std::vector< std::pair<int,int> > temp;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<=c;i++) scanf("%d%d",&P[i].first,&P[i].second);
	std::sort(P+1,P+c+1);
	
	for(int i=1;i<=c;i++)
	{
		if(P[i].first!=P[i-1].first) prev[i] = i;
		else prev[i] = prev[i-1];
	}
	for(int i=c;i>=1;i--)
	{
		if(P[i].first!=P[i+1].first) next[i] = i;
		else next[i] = next[i+1];
	}
	
	for(int i=1;i<=c;i++)
	{
		if(i==next[i])
		{
			for(int j=prev[i];j<=i;j++)
			{
				int min = 1, max = C-1;
				int p = 0;
				while(min<=max)
				{
					int h = (min+max)/2;
					if(check[h]<P[j].second)
					{
						p = h;
						min = h+1;
					}
					else max = h-1;
				}
				temp.push_back(std::make_pair(p+1,P[j].second));
			}
			
			while(!temp.empty())
			{
				std::pair<int,int> t = temp.back();
				temp.pop_back();
				if(t.first==C) C++, check[t.first] = t.second;
				else check[t.first] = check[t.first]<t.second?check[t.first]:t.second;
			}
		}
	}
	
	printf("%d",C-1);
}
0