Task: | Kortit II |
Sender: | urkkiz |
Submission time: | 2024-11-10 20:20:53 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | TIME LIMIT EXCEEDED | 0 |
#2 | TIME LIMIT EXCEEDED | 0 |
#3 | TIME LIMIT EXCEEDED | 0 |
#4 | TIME LIMIT EXCEEDED | 0 |
#5 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | TIME LIMIT EXCEEDED | -- | 1, 2, 3, 4, 5 | details |
#2 | TIME LIMIT EXCEEDED | -- | 2, 3, 4, 5 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
#4 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
#5 | TIME LIMIT EXCEEDED | -- | 5 | details |
#6 | TIME LIMIT EXCEEDED | -- | 5 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:91:13: warning: unused variable 'possibilities' [-Wunused-variable] 91 | int possibilities = 0; | ^~~~~~~~~~~~~ input/code.cpp:145:13: warning: unused variable 'start' [-Wunused-variable] 145 | int start = 0; | ^~~~~ input/code.cpp:154:13: warning: variable 'resLast' set but not used [-Wunused-but-set-variable] 154 | int resLast = 0; | ^~~~~~~ input/code.cpp:68:10: warning: variable 'foundOnIteration' set but not used [-Wunused-but-set-variable] 68 | bool foundOnIteration = true; | ^~~~~~~~~~~~~~~~ input/code.cpp:69:10: warning: variable 'foundOnIterationTwo' set but not used [-Wunused-but-set-variable] 69 | bool foundOnIterationTwo = true; | ^~~~~~~~~~~~~~~~~~~
Code
#include<iostream> #include<unordered_set> #include<unordered_map> #include<map> #include<algorithm> #include<iterator> using namespace std; bool unorderedSetContainsInt(unordered_set<int> set, int val){ return set.find(val) != set.end(); } int factorial(int num){ long long unsigned int result = 1; for(int i = 1; i <= num; i++){ result*=i; } return result; } struct pairHash { size_t operator()(const pair<int, int> &el) const{ return el.first ^ el.second; } }; struct pairIntArrayHash { size_t operator()(const std::pair<int*, int*>& p) const { size_t hash1 = std::hash<int>{}(*p.first); size_t hash2 =std::hash<int>{}( *p.second); return hash1 ^ (hash2 << 1); } }; unordered_set<pair<int, int>, pairHash> blackListedSwapsArrOne = {}; //deck one. unordered_set<pair<int, int>, pairHash> blackListedSwapsArrTwo = {}; //deck two. unordered_set<pair<int*, int*>, pairIntArrayHash> blackListedCombination = {}; unordered_set<int> blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK = {}; //deck the fucken whatever grgajhsdjhsadg fjhsadgfb woag!! //no columns. fuck you int printArray(int* arrOne, int* arrTwo, int range){ std::cout<<"\n"; for(int i = 0; i < range; i++){ std::cout << arrOne[i] + 1 << " "; } std::cout<<"\n"; for(int i = 0; i < range; i++){ std::cout << arrTwo[i] + 1 << " "; } std::cout << "\n\n"; return 0; } int main(){ int t; cin >> t; int cardMatrix[t][3]; for(int i = 0; i < t; i++){ /* cardMatrix[i][0]=100; cardMatrix[i][1]=1; cardMatrix[i][2]=2; */ for(int j = 0; j < 3; j++){ cin >> cardMatrix[i][j]; } } //something something forgot what i was writing unordered_map; //oh yea int foundMultiples = 0; bool foundOnIteration = true; bool foundOnIterationTwo = true; for(int i = 0; i < t; i++){ foundMultiples = 0x0; foundOnIteration = true; foundOnIterationTwo = true; int arrOne[cardMatrix[i][0]]; int arrTwo[cardMatrix[i][0]]; int arrOneCopy[cardMatrix[i][0]]; int arrTwoCopy[cardMatrix[i][0]]; int range = cardMatrix[i][0]; //cardMatrix[i][0]; // number of cards. int pointsP1 = cardMatrix[i][1]; //AKA points left. int pointsP2 = cardMatrix[i][2]; //handled as points left for(int jshjkhj = 0; jshjkhj < cardMatrix[i][0]; jshjkhj++){ arrOne[jshjkhj] = jshjkhj; arrTwo[jshjkhj] = jshjkhj; arrOneCopy[jshjkhj] = jshjkhj; arrTwoCopy[jshjkhj] = jshjkhj; } if(pointsP1 + pointsP2 > range || (pointsP1 == 0 && pointsP2 != 0) || (pointsP2 == 0 && pointsP1 != 0)){ std::cout << "0" << endl; continue; } int possibilities = 0; bool found = false; for(int j = 0; j < range; j++){ found = false; if(pointsP1 == 0 && pointsP2 == 0){ found = true; break; } if(j + pointsP1 + pointsP2 > range){ std::cout<<"0"<<endl; break; } if(pointsP1 >= pointsP2){ for(int m = 0; m < range; m++){ if(pointsP1 == pointsP2){ if(arrOne[range-(m+1)] > arrTwo[j]){ int temp = arrOne[j]; arrOne[j] = arrOne[range-(m+1)]; arrOne[range-(m+1)] = temp; pointsP1--; pointsP2--; break; } }else{ if(arrOne[m] > arrTwo[j] && arrOne[m] > arrTwo[j]){ int temp = arrOne[j]; arrOne[j] = arrOne[m]; arrOne[m] = temp; pointsP1--; break; } } } }else if(pointsP2 > pointsP1){ for(int m = 0; m < range; m++){ if(arrTwo[m] > arrOne[j] && arrTwo[m] > arrOne[j]){ int temp = arrTwo[j]; arrTwo[j] = arrTwo[m]; arrTwo[m] = temp; pointsP2--; break; } } } } if(found){ //printArray(arrOne, arrTwo, range); foundMultiples = 1; std::copy(arrOne, arrOne + range, arrOneCopy); std::copy(arrTwo, arrTwo + range, arrTwoCopy); }else{ std::cout<<"0"<<endl; continue; } int start = 0; unordered_map<int, int> timesSwappedAnyColumn; bool normalLoop = true; for(int i = 0; i < range; i++){ if(arrOne[i] == arrTwo[i]){ blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.insert(arrOne[i]); timesSwappedAnyColumn.insert({timesSwappedAnyColumn.size(), 0}); } } int resLast = 0; bool sizeIsOne = false; if(blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.size() == 0) sizeIsOne = true; int ptsLastIter = 0; int swapsForAnyColumn = 0; int columnsGoneThrough = blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.size(); //(lie) //blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.clear(); pointsP1 = cardMatrix[i][1]; pointsP2 = cardMatrix[i][2]; bool goneThruAllColumns = false; int totalTest = 0; blackListedCombination.insert({arrOne, arrTwo}); while(!goneThruAllColumns || sizeIsOne){ if(normalLoop){ while(true){ std::copy(arrOneCopy, arrOneCopy + range, arrOne); std::copy(arrTwoCopy, arrTwoCopy + range, arrTwo); ptsLastIter = foundMultiples; for(int j = 0; j < range; j++){ resLast = foundMultiples; normalLoop = false; foundOnIteration = false; for(int m = 0; m < range; m++){ foundOnIteration = false; if(arrOne[m] != arrOne[j] && arrOne[m] != arrTwo[m] && arrOne[j] != arrTwo[j] && arrOne[j] != arrTwo[m] && arrOne[m] != arrTwo[j]){ if(((arrOne[m] > arrTwo[j] && arrOne[j] > arrTwo[m])||(arrOne[m] < arrTwo[j] && arrOne[j] < arrTwo[m]) || (arrOne[m] > arrTwo[j] && arrOne[j] < arrTwo[m]) || (arrOne[m] < arrTwo[j] && arrOne[j] > arrTwo[m]))){ int temp = arrOne[m]; arrOne[m] = arrOne[j]; arrOne[j] = temp; bool isUnique = blackListedCombination.find({arrOne, arrTwo}) == blackListedCombination.end(); if(isUnique){ //std::cout<<"huh2"<<endl; blackListedCombination.insert({arrOne, arrTwo}); //std::cout << arrOne[j]+1 << " : " << arrOne[m]+1<< " (one) " <<endl; foundMultiples++; j = 0; //printArray(arrOne, arrTwo, range); } if(blackListedSwapsArrOne.find({arrOne[m], arrOne[j]})!=blackListedSwapsArrOne.end()){ //uhh do we need a fucking blacklist blacklist or what int temp = arrOne[m]; arrOne[m] = arrOne[j]; arrOne[j] = temp; } if(isUnique){ blackListedSwapsArrOne.insert({arrOne[m], arrOne[j]}); blackListedSwapsArrOne.insert({arrOne[j], arrOne[m]}); } //printArray(arrOne, arrTwo, range); foundOnIteration = true; //printArray(arrOne, arrTwo, range); for(int l = 0; l < range; l++){ for(int k = 0; k < range; k++){ if(arrTwo[k] != arrTwo[l] && arrOne[k] != arrTwo[k] && arrOne[l] != arrTwo[l] && arrOne[k] != arrTwo[l] && arrOne[l] != arrTwo[k]){ if((arrTwo[l] > arrOne[k] && arrTwo[k] > arrOne[l]) || (arrTwo[l] < arrOne[k]&&arrTwo[l] < arrOne[k]) || (arrTwo[l] > arrOne[k] && arrTwo[l] < arrOne[k])|| (arrTwo[l] < arrOne[k]&&arrTwo[l] > arrOne[k])){ //std::cout<<"yuh"<<endl; //std::cout << arrTwo[k]+1 << " : " << arrTwo[l]+1<< " (two) "<< endl; int temp = arrTwo[l]; arrTwo[l] = arrTwo[k]; arrTwo[k] = temp; bool isUnique = blackListedCombination.find({arrOne, arrTwo}) == blackListedCombination.end(); //std::cout<<(blackListedCombination.find({arrOne, arrTwo}) == blackListedCombination.end())<<endl; if(isUnique){ //std::cout << "huh" << endl; blackListedCombination.insert({arrOne, arrTwo}); foundMultiples++; //std::cout << arrTwo[k]+1 << " : " << arrTwo[l]+1<< " (two) "<< endl; j=0; l=0; //printArray(arrOne, arrTwo, range); } if(blackListedSwapsArrTwo.find({arrTwo[k], arrTwo[l]})==blackListedSwapsArrTwo.end()){ int temp = arrTwo[l]; arrTwo[l] = arrTwo[k]; arrTwo[k] = temp; } blackListedSwapsArrTwo.insert({arrTwo[l], arrTwo[k]}); blackListedSwapsArrTwo.insert({arrTwo[k], arrTwo[l]}); //printArray(arrOne, arrTwo, range); } } } } } } } } if(foundMultiples == ptsLastIter){ break; } } } else{ int nthColumn = 1; if(sizeIsOne) break; found = false; normalLoop = true; for (int m = 0; m < range; m++){ if(arrOneCopy[m] == arrTwoCopy[m]) { if (foundMultiples == 35){ std::cout<<totalTest<<endl; goneThruAllColumns = true; break; } if(totalTest == 3){ goneThruAllColumns = true; break; } //std::cout<<arrOneCopy[m]+1 << " : "<< arrTwoCopy[m]+1 << " : " << m<<endl; //make this work lol //std::cout<<timesSwappedFirstColumn<<" (timesSwappedFirstColumn) " << endl; //std::cout<<nthColumn << columnsGoneThrough<<endl; if(nthColumn+1 < columnsGoneThrough){ //std::cout<<nthColumn << columnsGoneThrough<<endl; nthColumn++; continue; } //std::cout<<swapsForAnyColumn<<endl; if(swapsForAnyColumn == pointsP1 + pointsP2 && timesSwappedAnyColumn[0] /*1st. i think*/ != range-pointsP1-pointsP2){ swapsForAnyColumn = 0; int backTrack = 0; //std::cout<<timesSwappedAnyColumn[0]<<"!!!?"<<endl; //std::cout<<timesSwappedAnyColumn[1]<<"!!222?"<<endl; //timesSwappedAnyColumn[nthColumn-backTrack] = 0; blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.clear(); while(true){ //std::cout<<nthColumn-backTrack<< " : " << range - pointsP1 - pointsP2 + 1 << " : " << timesSwappedAnyColumn[nthColumn-backTrack] << endl; if(timesSwappedAnyColumn[nthColumn - backTrack] == range - pointsP1 - pointsP2 + 1){ timesSwappedAnyColumn[nthColumn-backTrack] = 0; if(backTrack == range-pointsP1-pointsP2-1 && timesSwappedAnyColumn[nthColumn-backTrack + 1] == range-pointsP1-pointsP2-1){ goneThruAllColumns = true; break; } timesSwappedAnyColumn[nthColumn-backTrack] = 0; backTrack++; m--; columnsGoneThrough--; nthColumn--; }else{ timesSwappedAnyColumn[nthColumn - backTrack]++; //std::cout<<nthColumn-backTrack<< " : " << range - pointsP1 - pointsP2 + 1 << " : " << timesSwappedAnyColumn[nthColumn-backTrack] << endl; break; } break; } } //done for this index counter yees for(int ms /*holy shit microsoft*/ = 0; ms < range; ms++){ if(blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.find(arrOneCopy[ms]) == blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.end()){ if((arrOneCopy[m] > arrTwoCopy[ms] || arrOneCopy[m] < arrTwoCopy[ms]) && arrOneCopy[ms] != arrTwoCopy[ms]){ //cout<<"brhhhh"<<endl; swapsForAnyColumn++; //timesSwappedAnyColumn[nthColumn]++; blackListedSwapsArrOne.clear(); blackListedSwapsArrTwo.clear(); int js /*holy shit javascript*/ = 0; //something something swappedtolist for(; js < range; js++){ if(arrTwoCopy[js] == arrOneCopy[ms]) break; } blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.insert(arrOneCopy[m]); blackListedColumnsArrFUCKINGBOTHHWWWOOOOAAAHHHEXCLAMATIONMARK.insert(arrOneCopy[ms]); //maybe gotta add the other one too? idk blackListedCombination.clear(); int temp = arrOneCopy[m]; arrOneCopy[m] = arrOneCopy[ms]; arrOneCopy[ms] = temp; temp = arrTwoCopy[m]; arrTwoCopy[m] = arrTwoCopy[js]; arrTwoCopy[js] = temp; found = true; foundMultiples++; //printArray(arrOneCopy, arrTwoCopy, range); //std::cout<<"anotha!! also " << temp + 1 <<endl; totalTest++; } } if(found){ normalLoop = true; break; } } } if(found){ normalLoop = true; break; } } //printArray(arrOne, arrTwo, range); } } //std::cout << "YES" << endl; //printArray(arrOne, arrTwo, range); std::cout << foundMultiples * factorial(range) << endl; //std::cout<<(foundMultiples*factorial(range))<<endl; } }
Test details
Test 1
Group: 1, 2, 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
54 4 4 0 3 1 3 3 2 2 4 0 4 ... |
correct output |
---|
0 0 0 0 0 ... |
user output |
---|
(empty) |
Test 2
Group: 2, 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
284 6 1 0 5 0 2 7 1 5 7 7 5 ... |
correct output |
---|
0 0 35280 0 36720 ... |
user output |
---|
(empty) |
Test 3
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
841 19 3 12 19 19 13 19 7 13 20 11 15 ... |
correct output |
---|
40291066 0 0 0 0 ... |
user output |
---|
(empty) |
Test 4
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 15 12 6 7 1 6 44 4 26 6 6 5 ... |
correct output |
---|
0 5040 494558320 0 340694548 ... |
user output |
---|
(empty) |
Test 5
Group: 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 892 638 599 966 429 655 1353 576 1140 1403 381 910 ... |
correct output |
---|
0 0 0 249098285 0 ... |
user output |
---|
(empty) |
Test 6
Group: 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 2000 1107 508 2000 1372 249 2000 588 65 2000 1739 78 ... |
correct output |
---|
750840601 678722180 744501884 159164549 868115056 ... |
user output |
---|
(empty) |