제출 #1062912

#제출 시각아이디문제언어결과실행 시간메모리
1062912TlenekWodoru카니발 티켓 (IOI20_tickets)C++14
25 / 100
700 ms141120 KiB
#include<bits/stdc++.h> #include "tickets.h" using namespace std; struct Node { int x; int i,j; bool operator <(const Node &B)const { if(x==B.x) { if(i==B.i){return j<B.j;} else{return i<B.i;} } else{return x<B.x;} } }; int k,n,m,n2; vector<vector<int>>answer; vector<vector<Node>>Tab; vector<Node>Lista; vector<int>V1[1509],V2[1509]; int CzyZajal[1509]; bool CzyMozna(Node x) { int s1=0,s2=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(Tab[i][j]<x){s1++;} else{s2++;} } } return s1>=s2; } Node BinSearch() { int l=0; int p=(int)Lista.size()-1; while(l<p) { const int mid=(l+p)>>1; if(CzyMozna(Lista[mid])){p=mid;} else{l=mid+1;} } return Lista[l]; } long long find_maximum(int K, vector<vector<int>>A) { k=K; n = A.size(); n2=n/2; m = A[0].size(); answer.resize(n,vector<int>(m,-1)); for(int i=0;i<n;i++) { vector<Node>Temp; for(int j=0;j<m;j++) { Temp.push_back({A[i][j],i,j}); Lista.push_back({A[i][j],i,j}); } sort(Temp.begin(),Temp.end()); Tab.push_back(Temp); } sort(Lista.begin(),Lista.end()); Node xd=Lista[(int)Lista.size()/2]; long long wynik=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(Tab[i][j]<xd) { wynik-=Tab[i][j].x; V1[i].push_back(Tab[i][j].j); } else { wynik+=Tab[i][j].x; V2[i].push_back(Tab[i][j].j); } } } memset(CzyZajal,-1,sizeof(CzyZajal)); for(int i=0;i<k;i++) { int ile=0; for(int j=0;j<n;j++) { if(ile==n2){break;} if((int)V1[j].size()>0&&(int)V2[j].size()==0) { int u=V1[j].back(); V1[j].pop_back(); CzyZajal[j]=i; answer[j][u]=i; ile++; } } for(int j=0;j<n;j++) { if(ile==n2){break;} if((int)V1[j].size()>0&&CzyZajal[j]!=i) { int u=V1[j].back(); V1[j].pop_back(); CzyZajal[j]=i; answer[j][u]=i; ile++; } } for(int j=0;j<n;j++) { if(CzyZajal[j]!=i&&(int)V2[j].size()>0) { int u=V2[j].back(); V2[j].pop_back(); answer[j][u]=i; } } } allocate_tickets(answer); return wynik; }
#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...