QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#218342#7185. Poor Studentsucup-team1055WA 5ms4104kbC++203.0kb2023-10-18 03:18:512023-10-18 03:18:51

Judging History

This is the latest submission verdict.

  • [2023-10-18 03:18:51]
  • Judged
  • Verdict: WA
  • Time: 5ms
  • Memory: 4104kb
  • [2023-10-18 03:18:51]
  • Submitted

answer

#include <bits/stdc++.h>

#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template<class T>
bool chmin(T &a, T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

template<class T>
bool chmax(T &a, T b) {
    if(a >= b) return false;
    a = b;
    return true;
}

using namespace std;
int main(){
	int n, k; cin >> n >> k;

	vector c(n, vector<int>(k));
	rep(i,0,n){
		rep(j,0,k){
			cin >> c[i][j];
		}
	}

	// cap of EXAM -> DST
	vector<int> a(k);
	rep(i,0,k){
		cin >> a[i];
	}
	
	vector<set<pair<ll,int>>> alive_cost(k);

	// cost of EXAM i -> EXAM j
	vector dead_cost(k, vector<set<pair<ll,int>>>(k));
	rep(i,0,k){
		rep(j,0,n){
			alive_cost[i].insert(pair(c[j][i], j));
		}
	}

	ll ans = 0;

	rep(i,0,n){
		ll tar = 1e18;
		int fore_student = -1;
		int back_student = -1;
		int fore_exam = -1;
		int inst_exam = -1;
		rep(j,0,k){
			if (a[j] > 0){
				// SOLO
				auto itr = alive_cost[j].begin();
				if (chmin(tar, itr->first)){
					fore_student = itr->second;
					back_student = -1;
					fore_exam = j;
					inst_exam = -1;
				}
			}else{
				// DUAL
				auto itr = alive_cost[j].begin();
				rep(l,0,k){
					if (a[l] == 0) continue;
					if (j == l) continue;
					if (dead_cost[j][l].empty()) continue;
					auto itr2 = dead_cost[j][l].begin();
					if (chmin(tar, itr->first + itr2->first)){
						fore_student = itr->second;
						back_student = itr2->second;
						fore_exam = j;
						inst_exam = l;
					}
				}
			}
		}
		if (back_student == -1){
			assert(fore_student != -1);
			a[fore_exam] -= 1;

			// DEL ALIVE COST : fore_student
			rep(j,0,k){
				alive_cost[j].erase(pair(c[fore_student][j], fore_student));
			}

			// INS DEAD LIST [fore_exam] -> [j] : fore_student
			rep(j,0,k){
				if (j == fore_exam) continue;
				dead_cost[fore_exam][j].insert(
					pair(- c[fore_student][fore_exam] + c[fore_student][j], fore_student)
				);
			}
		}else{
			a[inst_exam] -= 1;

			// DEL DEAD LIST [fore_exam] -> [j] : back_student
			rep(j,0,k){
				if (j == fore_exam) continue;
				dead_cost[fore_exam][j].erase(
					pair(- c[back_student][fore_exam] + c[back_student][j], back_student)
				);
			}

			// INS DEAD LIST [inst_exam] -> [j] : back_student
			rep(j,0,k){
				if (j == inst_exam) continue;
				dead_cost[inst_exam][j].insert(
					pair(- c[back_student][inst_exam] + c[back_student][j], back_student)
				);
			}

			// DEL ALIVE COST : fore_student
			rep(j,0,k){
				alive_cost[j].erase(pair(c[fore_student][j], fore_student));
			}

			// INS DEAD LIST [fore_exam] -> [j] : fore_student
			rep(j,0,k){
				if (j == fore_exam) continue;
				dead_cost[fore_exam][j].insert(
					pair(- c[fore_student][fore_exam] + c[fore_student][j], fore_student)
				);
			}
		}

		ans += tar;

		//cout << ans << '\n';
	}

	cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3408kb

input:

6 2
1 2
1 3
1 4
1 5
1 6
1 7
3 4

output:

12

result:

ok answer is '12'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3468kb

input:

3 3
1 2 3
2 4 6
6 5 4
1 1 1

output:

8

result:

ok answer is '8'

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 4104kb

input:

1000 10
734 303 991 681 755 155 300 483 702 442
237 256 299 675 671 757 112 853 759 233
979 340 288 377 718 199 935 666 576 842
537 363 592 349 494 961 864 727 84 813
340 78 600 492 118 421 478 925 552 617
517 589 716 7 928 638 258 297 706 787
266 746 913 978 436 859 701 951 137 44
815 336 471 720 2...

output:

92190

result:

wrong answer expected '92039', found '92190'