제출 #171056

#제출 시각아이디문제언어결과실행 시간메모리
171056Ruxandra985Ice Hockey World Championship (CEOI15_bobek)C++14
100 / 100
488 ms8668 KiB
/// un meet in the middle mai basic si mai penal decat mine
#include <bits/stdc++.h>

using namespace std;
long long v[45] , w[2000000];
int conf[45];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , i , elem , st , dr , mid , p;
    long long sol , m , sum;
    fscanf (fin,"%d%lld",&n,&m);
    for (i=1;i<=n;i++)
        fscanf (fin,"%lld",&v[i]);
    sum = 0;
    elem = 0;
    w[++elem] = 0; /// multimea vida
    sol = 1;
    while (true){
        p = 1;
        while (conf[p] == 1){
            sum-=v[p];
            conf[p] = 0;
            p++;
        }

        if (p > n/2) /// 1 ... n/2
            break;

        conf[p] = 1;
        sum += v[p];

        if (sum <= m)
            sol++;

        w[++elem] = sum;

    }
    sort (w + 1 , w + elem + 1);
    sum = 0;
    conf[n/2+1] = 0;
    while (true){
        p = n/2 + 1; /// n/2 + 1 ... n
        while (conf[p] == 1){
            sum-=v[p];
            conf[p] = 0;
            p++;
        }

        if (p > n)
            break;

        conf[p] = 1;
        sum += v[p];

        st = 1;
        dr = elem;
        while (st <= dr){
            mid = (st + dr)/2;
            if (sum + w[mid] <= m)
                st = mid + 1;
            else dr = mid - 1;
        }

        sol += dr;

    }
    fprintf (fout,"%lld",sol);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bobek.cpp: In function 'int main()':
bobek.cpp:13:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%lld",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
bobek.cpp:15:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%lld",&v[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...