Submission #1048512
Source Code Expand
#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 Info
Submission Time |
|
Task |
D - grepマスター |
User |
tspcx |
Language |
C++11 (GCC 4.8.1) |
Score |
100 |
Code Size |
1592 Byte |
Status |
AC |
Exec Time |
109 ms |
Memory |
1956 KB |
Compile Error
./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);
^
Judge Result
Set Name |
All |
Score / Max Score |
100 / 100 |
Status |
|
Set Name |
Test Cases |
All |
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 |
Case Name |
Status |
Exec Time |
Memory |
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 |