結果

問題 No.110 しましまピラミッド
ユーザー data9824data9824
提出日時 2015-05-13 22:31:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 68,256 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 03:48:20
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:31: warning: narrowing conversion of ‘(c[0].std::vector<int>::size() - 1)’ from ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} to ‘int’ inside { } [-Wnarrowing]
   int next[2] = { c[0].size() - 1, c[1].size() - 1 };
                   ~~~~~~~~~~~~^~~
main.cpp:26:48: warning: narrowing conversion of ‘(c[1].std::vector<int>::size() - 1)’ from ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} to ‘int’ inside { } [-Wnarrowing]
   int next[2] = { c[0].size() - 1, c[1].size() - 1 };
                                    ~~~~~~~~~~~~^~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

int main() {
	int n;
	vector<int> c[2];
	cin >> n;
	c[0].resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> c[0][i];
	}
	cin >> n;
	c[1].resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> c[1][i];
	}
	sort(c[0].begin(), c[0].end());
	sort(c[1].begin(), c[1].end());
	int maxHeight = 0;
	for (int startColor = 0; startColor <= 1; ++startColor) {
		int color = startColor;
		int next[2] = { c[0].size() - 1, c[1].size() - 1 };
		int length = numeric_limits<int>::max();
		int height = 0;
		for (;;) {
			while (next[color] >= 0 && c[color][next[color]] >= length) {
				--next[color];
			}
			if (next[color] < 0) {
				break;
			}
			length = c[color][next[color]];
			--next[color];
			++height;
			color = 1 - color;
		}
		maxHeight = max(maxHeight, height);
	}
	cout << maxHeight << endl;
	return 0;
}
0