結果
| 問題 | 
                            No.369 足し間違い
                             | 
                    
| コンテスト | |
| ユーザー | 
                             alpha_virginis
                         | 
                    
| 提出日時 | 2016-06-05 07:39:14 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 883 bytes | 
| コンパイル時間 | 1,423 ms | 
| コンパイル使用メモリ | 157,412 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-08 14:09:13 | 
| 合計ジャッジ時間 | 1,895 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 5 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |   int N; scanf("%d", &N);
      |          ~~~~~^~~~~~~~~~
main.cpp:17:53: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |   Array<int> xs(N); for(int i = 0; i < N; ++i) scanf("%d", &xs.p[i]);
      |                                                ~~~~~^~~~~~~~~~~~~~~~
main.cpp:18:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   int v; scanf("%d", &v);
      |          ~~~~~^~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
template<typename T>
class Array {
public:
  T* p; int size; int seek;
  Array(int N) { p = new T[N]; size = N; seek = 0; }
  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; }
template<typename T> T add(const T& x, const T& y) { return x + y; }
int main() {
  int N; scanf("%d", &N);
  Array<int> xs(N); for(int i = 0; i < N; ++i) scanf("%d", &xs.p[i]);
  int v; scanf("%d", &v);
  int res = foldl1(xs, add<int>) - v;
  printf("%d\n", res);
  
  return 0;
}
            
            
            
        
            
alpha_virginis