結果

問題 No.77 レンガのピラミッド
ユーザー かにかに
提出日時 2015-12-04 21:59:57
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,187 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 146,584 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 14:32:21
合計ジャッジ時間 2,424 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 RE -
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:33:6: warning: ‘top’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  int top;
      ^~~

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define P(p) cout<<(p)<<endl;
#define pi 3.1415926535
using namespace std;
typedef long long ll;
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

unsigned long long sttoi(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ll gcd(ll a, ll b){
	if (b > a)swap(a, b); if (b == 0)return a; else{ return gcd(b, a%b); }
}

void solve() {
	int v[1000];
	int sum = 0;
	int n;
	cin >> n;
	fill(v, v + 1000, 0);
	for (int i = 1; i <= n;i++){
		cin >> v[i];
		sum += v[i];
	}
	int top;
	int s = 1;
	if (s == sum){
		top == 1;
	}
	else{
		for (int i = 1;; i++){
			if (s + 2 * i + 1 <= sum){
				top = i + 1;
				s += 2 * i + 1;
			}
			else{
				break;
			}
		}
	}
	int height[10000];
	fill(height, height + 10000, 0);
	for (int i = 1; i <= top;i++){
		height[i] = i;
		height[i + (top - i) * 2] = i;
	}
	int need = 0;
	int left = 0;
	for (int i = 1; i <= n; i++){
		int gap = v[i] - height[i];
		if (gap < 0){
			need += gap;
		}
		else{
			left += gap;
		}
	}
	P(left);
}

int main() {
	solve();
	return 0;
}
0