CODE FESTIVAL 2016 Final

Submission #995210

Source codeソースコード

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <limits>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define x first
#define y second
#define sf scanf
#define pf printf
#define vec vector
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define bin_cnt(x) __builtin_popcount(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define srep(sub,s) for(int sub=s&(s-1);sub;sub=(sub-1)&s)
#define irep(i,a) for(__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define irrep(i,a) for(__typeof(a.rbegin()) i=a.rbegin();i!=a.rend();i++)
#define inf numeric_limits<int>::max()
#define finf numeric_limits<double>::infinity()
#define eps 1e-8
#pragma GCC optimize ("O3")
#define o3 __attribute__((optimize("O3")))
#pragma comment(linker, "/STACK:32505856")

template<class T> inline T sqr(T a) {return a*a;}
template<class T> inline int gmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> inline int gmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
inline int dcmp(const double &a) {return a>eps?1:(a<-eps?-1:0);}
struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}}initializer;

#define N 2000010
int n, m, a[N];
int pos1, pos2, sum1, sum2;
int sum[N];

#define T 4000020
#define idx(l,r) ((l+r)|(l!=r))
int maxv[T], tpos[T];
int P, Q, V, NP;
int base;

void insert(int l, int r) {
  int x = idx(l, r);
  if (l == r) {
    maxv[x] = V;
    return;
  }
  int m = l + r >> 1;
  int lx = idx(l, m);
  int rx = idx(m + 1, r);
  if (P <= m) insert(l, m);
         else insert(m + 1, r);

  maxv[x] = maxv[lx];
  tpos[x] = tpos[lx];
  if (gmax(maxv[x], maxv[rx])) tpos[x] = tpos[rx];
}

void select(int l, int r) {
  int x = idx(l, r);
  if (P <= l && r <= Q) {
    if (gmax(V, maxv[x])) {
        NP = tpos[x];
    }
    return;
  }
  int m = l + r >> 1;
  if (P<=m) select(l, m);
  if (Q> m) select(m + 1, r);
}


int main() {
//    freopen("in.txt","r",stdin);

    sf("%d", &n);
    int n2 = 2 * n;
    rep(i, 0, n2) {
        maxv[i] = -inf;
    }
    rep(i, 1, n - 1) {
        sf("%d", a + i);
        sum[i] = a[i] + sum[i - 1];
        P = i;
        V = a[i] - (sum[i] - sum[2]);
        insert(1, n);
    }
    sf("%d", &m);
//    pf("%d %d\n",pos1 + pos2 , n + n - 1);
    rep(i, 1, m) {
        sf("%d", a + n);
        sum[n] = a[n] + sum[n - 1];
        pos1 = 1;
        pos2 = 2;
        sum1 = a[1];
        sum2 = a[2];
        while (pos1 + pos2 < n + n - 1) {
                pf("[%d,%d]\n",pos1,pos2);
            if (pos1 < pos2) {
                P = pos2 + 1,
                Q = n,
                V = -inf,
                NP = pos2 + 1;
                select(1, n);

                pos1 = NP;
                sum1 += V - base;
                base += sum[NP] - sum[pos2];

            } else {

                P = pos1 + 1,
                Q = n,
                V = -inf,
                NP = pos1 + 1;
                select(1, n);

                pos2 = NP;
                sum2 += V - base;
                base += sum[NP] - sum[pos1];
            }
        }
        pf("%d\n", sum1 - sum2);
    }
    return 0;
}

Submission

Task問題 H - Tokaido
User nameユーザ名 alpc104
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 3618 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:94:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", &n);
^
./Main.cpp:100:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", a + i);
^
./Main.cpp:106:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", &m);
^
./Main.cpp:109:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", a + n);
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
dataset1 0 / 700 sample-01.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt
dataset2 0 / 900 sample-01.txt,sample-02.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,02-01.txt,02-02.txt,02-03.txt,02-04.txt,02-05.txt,02-06.txt,02-07.txt,02-08.txt,02-09.txt,02-10.txt,02-11.txt,02-12.txt,02-13.txt,02-14.txt,02-15.txt,02-16.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt TLE
01-02.txt WA
01-03.txt TLE
01-04.txt TLE
01-05.txt TLE
01-06.txt TLE
01-07.txt TLE
01-08.txt TLE
01-09.txt TLE
01-10.txt TLE
01-11.txt TLE
01-12.txt TLE
01-13.txt TLE
01-14.txt TLE
01-15.txt TLE
01-16.txt TLE
01-17.txt TLE
01-18.txt TLE
01-19.txt TLE
02-01.txt TLE
02-02.txt TLE
02-03.txt TLE
02-04.txt TLE
02-05.txt TLE
02-06.txt TLE
02-07.txt TLE
02-08.txt TLE
02-09.txt TLE
02-10.txt TLE
02-11.txt TLE
02-12.txt TLE
02-13.txt TLE
02-14.txt TLE
02-15.txt TLE
02-16.txt TLE
sample-01.txt TLE
sample-02.txt TLE