Submission #1851

# Submission time Handle Problem Language Result Execution time Memory
1851 2013-07-19T02:30:47 Z alephnull 대표 선수 (KOI11_player) C++
0 / 20
0 ms 904 KB
#include <cstdio>
#include <algorithm>
#include <ctime>
#include <utility>
#include <vector>
#include <functional>
using namespace std;
int main(){
	//freopen("input.txt","r",stdin);
 	clock_t start_time, end_time;

    start_time = clock();
    int n,m;scanf("%d %d",&n,&m);
    int *a[1000];
    for(int i=0;i<n;i++)a[i]=new int[1000];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            scanf("%d",&a[i][j]);
    for(int i=0;i<n;i++)
        sort(a[i],a[i]+m);

    int ans=987654321;
    int p[1000];
    for(int i=0;i<n;i++)p[i]=0;
    pair<int,int> tmp[1000];
    for(int i=0;i<n;i++)tmp[i]=make_pair(a[i][p[i]],i);
    int max=0;
    for(int i=0;i<n;i++)if(max<a[i][p[i]])max=a[i][p[i]];
    vector<pair<int,int> >min(tmp,tmp+n);
    make_heap(min.begin(),min.end(),greater<pair<int,int> >());
    while(1){
    	if(ans>max-min.front().first)ans=max-min.front().first;
    	int idx=min.front().second;
    	if(p[idx]==m-1)break;
    	//printf("%d %d\n",idx,p[idx]);
    	p[idx]++;
    	if(a[idx][p[idx]]>max)max=a[idx][p[idx]];
    	pop_heap (min.begin(),min.end(),greater<pair<int,int> >()); min.pop_back();
    	min.push_back(make_pair(a[idx][p[idx]],idx)); push_heap(min.begin(),min.end(),greater<pair<int,int> >());
    }
    end_time = clock();
    //printf("Time : %f\n", ((double)(end_time-start_time)) / CLOCKS_PER_SEC);
    printf("%d\n",ans);

}
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
2 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
3 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
4 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
5 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
2 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
3 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
4 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
5 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
2 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
3 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
4 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
5 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
6 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
7 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
8 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
9 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)
10 Runtime error 0 ms 904 KB times (syscall #100) was called by the program (disallowed syscall)