Submission #203196

# Submission time Handle Problem Language Result Execution time Memory
203196 2020-02-19T19:10:14 Z MKopchev Sticks (POI11_pat) C++14
100 / 100
403 ms 13540 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42,inf=2e9+42,kmax=50+5;

int k;
pair<int/*length*/,short/*colour*/> inp[nmax];
int pointer;

vector<int> seen[kmax];

int last_seen[kmax];

bool is_less(pair<int/*length*/,int/*colour*/> a,pair<int/*length*/,int/*colour*/> b)
{
    return a.first<b.first;
}

int furthest(int colour,int up_to)
{
    int ok=0,not_ok=seen[colour].size();
    while(not_ok-ok>1)
    {
        int av=(ok+not_ok)/2;
        if(seen[colour][av]<=up_to)ok=av;
        else not_ok=av;
    }
    return seen[colour][ok];
}
int main()
{
    scanf("%i",&k);

    int SZ,current;
    for(int i=1;i<=k;i++)
    {
        scanf("%i",&SZ);
        for(int j=1;j<=SZ;j++)
        {
            scanf("%i",&current);
            seen[i].push_back(current);
            pointer++;
            inp[pointer]={current,i};
        }
        sort(seen[i].begin(),seen[i].end());
    }

    for(int i=1;i<=k;i++)last_seen[i]=inf;

    sort(inp+1,inp+pointer+1);
    for(int i=pointer;i>=1;i--)
    {
        pair<int/*length*/,int/*colour*/> best={inf,0},second_best={inf,0},current;
        for(int j=1;j<=k;j++)
            if(j!=inp[i].second)
            {
                current={last_seen[j],j};
                if(is_less(current,best))second_best=best,best=current;
                else if(is_less(current,second_best))second_best=current;
            }

        if(second_best.first<inf)
        {
            best.first=furthest(best.second,second_best.first);
            if(inp[i].first+best.first>second_best.first)
            {
                printf("%i %i %i %i %i %i\n",inp[i].second,inp[i].first,best.second,best.first,second_best.second,second_best.first);
                return 0;
            }
        }
        last_seen[inp[i].second]=inp[i].first;
    }

    printf("NIE\n");
    return 0;
}

Compilation message

pat.cpp: In function 'int main()':
pat.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&k);
     ~~~~~^~~~~~~~~
pat.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&SZ);
         ~~~~~^~~~~~~~~~
pat.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%i",&current);
             ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Oczekiwano NIE
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Oczekiwano NIE
2 Correct 21 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Oczekiwano NIE
2 Correct 21 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 504 KB Oczekiwano NIE
2 Correct 46 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 888 KB Oczekiwano NIE
2 Correct 72 ms 3128 KB Output is correct
3 Correct 49 ms 2568 KB Oczekiwano NIE
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1784 KB Oczekiwano NIE
2 Correct 119 ms 4368 KB Output is correct
3 Correct 80 ms 3204 KB Oczekiwano NIE
# Verdict Execution time Memory Grader output
1 Correct 209 ms 7272 KB Output is correct
2 Correct 154 ms 7448 KB Output is correct
3 Correct 111 ms 5536 KB Oczekiwano NIE
# Verdict Execution time Memory Grader output
1 Correct 199 ms 7280 KB Output is correct
2 Correct 157 ms 8044 KB Output is correct
3 Correct 145 ms 6552 KB Oczekiwano NIE
# Verdict Execution time Memory Grader output
1 Correct 403 ms 13540 KB Output is correct
2 Correct 176 ms 9200 KB Output is correct
3 Correct 206 ms 10092 KB Oczekiwano NIE
# Verdict Execution time Memory Grader output
1 Correct 398 ms 13388 KB Output is correct
2 Correct 203 ms 10360 KB Output is correct
3 Correct 248 ms 11088 KB Oczekiwano NIE