Submission #5371

# Submission time Handle Problem Language Result Execution time Memory
5371 2014-04-16T08:51:20 Z baneling100 대표 선수 (KOI11_player) C++
20 / 20
308 ms 5124 KB
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#define inf 0x7fffffff

using namespace std;

typedef pair <int,int> ppair;
priority_queue <ppair,vector<ppair>,greater<ppair> > q;
int n, m, a[1001][1001], ans=inf;

void input(void)
{
    int i, j;

    scanf("%d %d",&n,&m);
    for(i=1 ; i<=n ; i++)
    {
        for(j=1 ; j<=m ; j++)
            scanf("%d",&a[i][j]);
        sort(a[i]+1,a[i]+m+1);
    }
}

void process(void)
{
    int i, ptr[1001], mmax=-inf, mmin, minv;

    for(i=1 ; i<=n ; i++)
    {
        ptr[i]=1;
        q.push(make_pair(a[i][1],i));
        if(mmax<a[i][1])
            mmax=a[i][1];
    }
    while(1)
    {
        mmin=q.top().first;
        minv=q.top().second;
        q.pop();
        if(ans>mmax-mmin)
            ans=mmax-mmin;
        ptr[minv]++;
        if(ptr[minv]>m)
            break;
        q.push(make_pair(a[minv][ptr[minv]],minv));
        if(mmax<a[minv][ptr[minv]])
            mmax=a[minv][ptr[minv]];
    }
}

void output(void)
{
    printf("%d",ans);
}

int main(void)
{
    input();
    process();
    output();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5124 KB Output is correct
2 Correct 0 ms 5124 KB Output is correct
3 Correct 0 ms 5124 KB Output is correct
4 Correct 0 ms 5124 KB Output is correct
5 Correct 0 ms 5124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5124 KB Output is correct
2 Correct 8 ms 5124 KB Output is correct
3 Correct 28 ms 5124 KB Output is correct
4 Correct 68 ms 5124 KB Output is correct
5 Correct 72 ms 5124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 5124 KB Output is correct
2 Correct 96 ms 5124 KB Output is correct
3 Correct 116 ms 5124 KB Output is correct
4 Correct 132 ms 5124 KB Output is correct
5 Correct 160 ms 5124 KB Output is correct
6 Correct 200 ms 5124 KB Output is correct
7 Correct 236 ms 5124 KB Output is correct
8 Correct 244 ms 5124 KB Output is correct
9 Correct 276 ms 5124 KB Output is correct
10 Correct 308 ms 5124 KB Output is correct