結果

問題 No.77 レンガのピラミッド
ユーザー itezpaceitezpace
提出日時 2016-08-05 08:35:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 896 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 63,996 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 15:36:19
合計ジャッジ時間 1,292 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
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 WA -
testcase_23 WA -
testcase_24 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:19: warning: ‘d’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |     for(int i=0; i<m; ++i){
      |                  ~^~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,a,b,c,d,e,f,g,h,k,m,vs,l,x;
  cin>>n;
  vector<int> v;
  b=0;
  for(int i=0; i<n; ++i){
    cin>>a;
    b+=a;
    v.push_back(a);
  }
  e=0;
  for(int i=1; i<=100; i+=2){
    c=0;
    for(int j=i; j>0; j-=2){
      c+=j;
      if(c>b){
        break;
      } else if(j==1){
        d=i;
        e=c;
      }
    }
  }
  f=b-e;
  g=0;
  k=0;
  m=abs(d-n);
  if(d>=n){
    for(int i=0; i<m; ++i){
      v.push_back(0);
    }
  } else {
    vs=v.size();
    for(int i=0; i<m; ++i){
      l=v[vs-i];
      g+=l;
      v[vs-i]=-1;
    }
    for(int i=0; i<m; ++i){
      v.erase(v.begin()+d);
    }
  }
  vs=v.size();
  for(int i=0; i<vs/2+1; ++i){
    h=abs(v[i]-(i+1));
    g+=h;
  }
  for(int i=vs/2+1; i<vs; ++i){
    h=abs(v[i]-(i-1));
    g+=h;
  }
  x=(g-f)/2+f;
  cout<<x<<endl;
  return 0;
}
0