AtCoder Regular Contest 014

Submission #1048512

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int a, n, m;
  scanf("%d %d %d", &a, &n, &m);
  vi l(n);
  rep (i, n) {
    scanf("%d", &l[i]);
    l[i] -= 1;
  }
  vi space(n-1);
  int left = l[0];
  FOR (i, 1, n) {
    space[i-1] = l[i] - l[i-1] - 1;
  }
  int right = a-1 - l[n-1];
  sort(all(space));
  vi sum(n, 0);
  FOR (i, 1, n) {
    sum[i] = sum[i-1] + space[i-1];
  }

  int x, y;
  int ans;
  rep (tmp, m) {
    ans = n;
    scanf("%d %d", &x, &y);
    ans += min(left, x);
    ans += min(right, y);
    int z = x + y;
    int filled = upper_bound(all(space), z) - begin(space);
    ans += sum[filled];
    ans += (z * (n-1 - filled));
    printf("%d\n", ans);
  }

  return 0;
}

Submission

Task問題 D - grepマスター
User nameユーザ名 gosenoku
Created time投稿日時
Language言語 C++11 (GCC 4.8.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1592 Byte
File nameファイル名
Exec time実行時間 109 ms
Memory usageメモリ使用量 1956 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:40:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &a, &n, &m);
^
./Main.cpp:43:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &l[i]);
^
./Main.cpp:62:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &x, &y);
^

Test case

Set

Set name Score得点 / Max score Cases
All 100 / 100 00_sample_01.txt,00_sample_02.txt,01_min.txt,02_rand_00.txt,02_rand_01.txt,02_rand_02.txt,03_randp_00.txt,03_randp_01.txt,03_randp_02.txt,04_maxrandp_00.txt,04_maxrandp_01.txt,04_maxrandp_02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01.txt AC 20 ms 796 KB
00_sample_02.txt AC 18 ms 800 KB
01_min.txt AC 18 ms 796 KB
02_rand_00.txt AC 67 ms 1700 KB
02_rand_01.txt AC 84 ms 1560 KB
02_rand_02.txt AC 34 ms 1180 KB
03_randp_00.txt AC 64 ms 1816 KB
03_randp_01.txt AC 92 ms 1824 KB
03_randp_02.txt AC 97 ms 1440 KB
04_maxrandp_00.txt AC 103 ms 1948 KB
04_maxrandp_01.txt AC 107 ms 1956 KB
04_maxrandp_02.txt AC 109 ms 1952 KB