結果

問題 No.369 足し間違い
ユーザー alpha_virginisalpha_virginis
提出日時 2016-06-04 12:18:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 158,648 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 00:16:58
合計ジャッジ時間 2,143 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void get(int&)’:
main.cpp:10:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 | void get(int& x) { scanf("%d", &x); }
      |                    ~~~~~^~~~~~~~~~
main.cpp: In constructor ‘Int::Int()’:
main.cpp:6:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |   Int() { scanf("%ld", &x); }
      |           ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

class Int {
public:
  long x;
  Int() { scanf("%ld", &x); }
  operator long() { return x; }
};

void get(int& x) { scanf("%d", &x); }

template<typename T> T add(const T& x, const T& y) { return x + y; }

template<typename T>
class Array {
public:
  T* p; int size; int seek;
  Array(int N) { p = new T[N]; size = N; seek = 0; for(int i = 0; i < N; ++i) get(p[i]); }
  Array(int N, T x) { p = new T[N]; for(int i = 0; i < N; ++i) p[i] = x; size = N; seek = 0; }
  const T& operator() (int i) const { return p[i]; }
};
template<typename T> inline Array<T> update(Array<T>& xs, int i, const T& x) { Array<T> res = xs; res.p[i] = x; xs.p = nullptr; return res; }
template<typename T, typename U> inline T foldl1(Array<T>& xs, U f) { T res = xs(0); for(int i = 1; i < xs.size; ++i) { res = f(res, xs(i)); } return res; }

int main() {
  Int N;
  Array<int> A(N);
  Int v;
  int res = foldl1(A, add<int>) - v;
  printf("%d\n", res);
  
  return 0;
}
0