CSES - Datatähti 2025 alku - Results
Submission details
Task:Niitty
Sender:urkkiz
Submission time:2024-11-10 22:39:39 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
#60
Test results
testverdicttimegroup
#10.00 s1, 2, 3, 4, 5, 6details
#2ACCEPTED0.00 s1, 2, 3, 4, 5, 6details
#30.00 s1, 2, 3, 4, 5, 6details
#40.00 s1, 2, 3, 4, 5, 6details
#5ACCEPTED0.00 s1, 2, 3, 4, 5, 6details
#60.00 s2, 3, 4, 5, 6details
#70.00 s2, 3, 4, 5, 6details
#80.00 s2, 3, 4, 5, 6details
#90.00 s2, 3, 4, 5, 6details
#100.01 s3, 4, 5, 6details
#110.01 s3, 4, 5, 6details
#120.01 s3, 4, 5, 6details
#130.01 s3, 4, 5, 6details
#140.01 s4, 5, 6details
#150.01 s4, 5, 6details
#160.01 s4, 5, 6details
#170.01 s4, 5, 6details
#180.05 s5, 6details
#190.05 s5, 6details
#200.04 s5, 6details
#210.05 s5, 6details
#220.45 s6details
#230.41 s6details
#240.40 s6details
#250.40 s6details

Compiler report

input/code.cpp:124: warning: ignoring '#pragma region iteration' [-Wunknown-pragmas]
  124 | #pragma region iteration down rows.
      | 
input/code.cpp:177: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
  177 |     #pragma endregion
      | 
input/code.cpp:178: warning: ignoring '#pragma region iteration' [-Wunknown-pragmas]
  178 |     #pragma region iteration in rows left and right.
      | 
input/code.cpp:253: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
  253 | #pragma endregion
      | 
input/code.cpp: In function 'int main()':
input/code.cpp:103:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |         for (int i = 0; i < s.size(); i++) {
      |                         ~~^~~~~~~~~~
input/code.cpp:119:10: warning: unused variable 'restAreImpossible' [-Wunused-variable]
  119 |     bool restAreImpossible = false;
      |...

Code

#include<iostream>
#include<list>
#include<algorithm>
#include<tuple>
#include<unordered_map>
#include<map>
using namespace std;
unordered_map<char, int> uniqueFlowers; //unique characters.
map<int, unordered_map<char, int>> charsPerRow;
map<int, unordered_map<char, int>> charsPerColumn;
//first element of tuple is amount, second element is index.
int amountOfCharInUniqueFlowers(char ch)
{
if(uniqueFlowers.find(ch) != uniqueFlowers.end())
return uniqueFlowers[ch];
return 0;
}
int amountOfCharInUniqueFlowersCustomListModify(char ch, unordered_map<char, int>& mapToModify)
{
if(mapToModify.find(ch) != mapToModify.end()){
mapToModify[ch]--;
return mapToModify[ch];
}
return 0;
}
int subtractUniqueFlowersCustomListModifyByRangeX(int row, int start, int end, unordered_map<char, int>& mapToModify, string* niitty)
{
for(int i = start; i <= end; i++){
if(mapToModify[niitty[row][i]] - 1 == 0)
return -1;
mapToModify[niitty[row][i]]--;
}
return 0;
}
int subtractUniqueFlowersCustomListModifyByRangeY(int column, int start, int end, unordered_map<char, int>& mapToModify, string* niitty)
{
for(int i = start; i <= end; i++){
if(mapToModify[niitty[i][column]] - 1 == 0){
return -1;
}
mapToModify[niitty[i][column]]--;
}
return 0;
}
//since this is
int uniqueFlowersContains(char ch)
{
if(uniqueFlowers.find(ch) != uniqueFlowers.end()){
uniqueFlowers[ch]++;
return uniqueFlowers[ch];
}
return 0;
}
int getNumOfCharInString(string s, char ch) {
int hits = 0;
for (char c : s) {
if (c == ch)
hits++;
}
return hits;
}
int subtractMatchingKeyValues(unordered_map<char, int>& one, unordered_map<char, int> minus){
for(const auto &[k,v] : one){
one[k] -= minus[k]; //always has this value.
if(one[k]<=0)
return -1;
}
return 0;
}
int subtractMatchingKeyValuesArr(unordered_map<char, int>& one, unordered_map<char, int>* minus){
for(const auto &[k,v] : one){
for(auto &[kk,vv] : *minus){
if(kk==k)
one[k] -= vv; //always has this value.
if(one[k]<=0)
return -1;
}
}
return 0;
}
bool intListContains(list<int> ls, int val) {
return std::find(ls.begin(), ls.end(), val) != ls.end();
}
int main() {
int SideLength = 0;
cin >> SideLength;
string niitty[SideLength] = {};
for (int i = 0; i < SideLength; i++) {
string newFieldRow = "";
cin >> newFieldRow;
niitty[i] = newFieldRow;
//50.
//niitty [i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABC";
//500.
//niitty [i] = "ABCDEFABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCDABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVAABCDEFABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCDABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCDABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCDABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCDGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCDABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCDABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCDABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCABCD";
//200.
//niitty [i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCXYZWABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCXYZWABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCXYZWABCDEFGHIJKLMNOPQRSTUVWXYZFGHIJKLMNOPQRSTUVABCXYZW";
//balls.
//niitty[i] = "AABABABABAAAAAAAAAABABABABAAAAAAAAABABAAAABBAAABAB";
}
for (string s : niitty) {
for (int i = 0; i < s.size(); i++) {
if (uniqueFlowersContains(s[i]) == 0){
uniqueFlowers.insert({ s[i], 1 });
}
}
}
/*
for(tuple<int, char> tup : uniqueFlowers){
std::cout << get<0>(tup) << " : " << get<1>(tup) << endl;
}
for(const auto &[k,v] : uniqueFlowers){
std::cout<<k<<" : " <<v <<endl;
}
*/
int possibleFoundBoxes = 1;
int uniqueFlowersCount = uniqueFlowers.size(); //wah wah wah "but 1 bit allocation!!! just use uniqueflowerscount wah wah!!" SHUT THE FUCK UP!
bool restAreImpossible = false;
//lists for impossible rows??? as in "jos tämä rivi otetaan pois niin ei enää toimi" (row list blacklist for x amd y dimensions)
//here it is. consider 2 other list when going from lower left corner to upper right instead of from upper left to lower right
list<int> blackListedRowsXdirection; //in 2nd.
list<int> blackListedRowsYdirection; //in 1st. WHAT the FUCK are you talking about -me later
#pragma region iteration down rows.
unordered_map<char, int> subtractedFlowers = uniqueFlowers;
bool found = false;
int newPossibleFound = 1;
unordered_map<char, int> tempMapColumns;
for (int i = 0; i < SideLength; i++) {
found = false;
tempMapColumns.clear();
if ((SideLength - i) * SideLength < uniqueFlowersCount)
break;
for (char c : niitty[i]) {
int numOfChar = getNumOfCharInString(niitty[i], c);
if (numOfChar >= amountOfCharInUniqueFlowers(c)) {
found = true;
blackListedRowsYdirection.push_front(i);
newPossibleFound = 0;
}else if(!found)https://www.onlinegdb.com/edit/zYdzjCPT5M#
tempMapColumns.insert({c, numOfChar});
}
possibleFoundBoxes+=newPossibleFound;
if(!found)
charsPerRow.insert({i, tempMapColumns});
if(subtractMatchingKeyValues(subtractedFlowers, tempMapColumns) == -1)
newPossibleFound = 0;
}
//std::cout << " y+ : " << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
//careful not to check for boxes that have already been checked.
subtractedFlowers = uniqueFlowers;
newPossibleFound = 1;
for (int i = SideLength - 1; i > 0; i--) {
found = false;
tempMapColumns.clear();
if (i * SideLength < uniqueFlowersCount)
break;
for (char c : niitty[i]) {
//std::cout<<"c: "<< c<<" has: "<< amountOfCharInUniqueFlowers(c)<<endl;
int numOfChar = getNumOfCharInString(niitty[i], c);
if (numOfChar >= amountOfCharInUniqueFlowers(c)) {
found = true;
blackListedRowsYdirection.push_front(i);
newPossibleFound = 0;
}else
tempMapColumns.insert({c, numOfChar});
}
possibleFoundBoxes+=newPossibleFound;
if(!found)
charsPerRow.insert({i, tempMapColumns});
if(subtractMatchingKeyValues(subtractedFlowers, tempMapColumns) == -1)
newPossibleFound = 0;
}
//std::cout << " y- : " << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
#pragma endregion
#pragma region iteration in rows left and right.
subtractedFlowers = uniqueFlowers;
newPossibleFound = 1;
unordered_map<char, int> xRowList;
for (int i = 0; i < SideLength; i++) {
found = false;
xRowList = uniqueFlowers;
if ((SideLength - i) * SideLength < uniqueFlowersCount) //possible ++ for impossibleboxes needed here?
break;
for (int j = 0; j < SideLength; j++) {
if (amountOfCharInUniqueFlowersCustomListModify(niitty[j][i], xRowList) == 0) {
found = true;
newPossibleFound = 0;
blackListedRowsXdirection.push_front(i);
}else{
if(tempMapColumns.find(niitty[j][i]) != tempMapColumns.end())
tempMapColumns[niitty[j][i]]++;
else
tempMapColumns.insert({niitty[j][i],1});
}
}
if(!found)
charsPerColumn.insert({i, tempMapColumns});
possibleFoundBoxes += newPossibleFound;
if(subtractMatchingKeyValues(subtractedFlowers, tempMapColumns) == -1)
newPossibleFound = 0;
}
//std::cout << " x+ : " << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
subtractedFlowers = uniqueFlowers;
newPossibleFound = 1;
for (int i = SideLength - 1; i > 0; i--) {
found = false;
xRowList = uniqueFlowers;
for (int j = 0; j < SideLength; j++) {
if (amountOfCharInUniqueFlowersCustomListModify(niitty[j][i], xRowList) == 0) {
found = true;
newPossibleFound = 0;
blackListedRowsXdirection.push_front(i);
}else{
if(tempMapColumns.find(niitty[j][i]) != tempMapColumns.end())
tempMapColumns[niitty[j][i]]++;
else
tempMapColumns.insert({niitty[j][i],1});
}
}
if(!found)
charsPerColumn.insert({i, tempMapColumns});
possibleFoundBoxes += newPossibleFound;
if(subtractMatchingKeyValues(subtractedFlowers, tempMapColumns) == -1)
newPossibleFound = 0;
}
//std::cout << " x- : " << possibleFoundBoxes << endl;
/*
for (const auto &[k, v] : charsPerRow){
std::cout << k << ": y" << endl;
for(const auto &[kk,vv] : charsPerRow[k]){
std::cout << kk << " : " << vv << endl;
}
}
for (const auto &[k, v] : charsPerColumn){
std::cout << k << ": x" << endl;
for(const auto &[kk,vv] : charsPerColumn[k]){
std::cout << kk << " : " << vv << endl;
}
}
*/
/*
for(int i : blackListedRowsXdirection){
std::cout << "xbl : " << i <<endl;
}
for(int i : blackListedRowsYdirection){
std::cout << "ybl : " << i << endl;
}
*/
#pragma endregion
//possibleFoundBoxes = 0;
int isEvenMatrix = SideLength % 2 == 0;
subtractedFlowers = uniqueFlowers;
for (int i = 0; i < SideLength/2 - isEvenMatrix; i++) {
if(subtractMatchingKeyValuesArr(subtractedFlowers, &(charsPerColumn[SideLength-(i+1)], charsPerColumn[i])) == -1)
break;
if (!intListContains(blackListedRowsXdirection, i) && !intListContains(blackListedRowsXdirection, SideLength - (i+1))) {
possibleFoundBoxes++;
}
}
//std::cout << " x -><-" << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
subtractedFlowers = uniqueFlowers;
for (int i = 0; i < SideLength/2 - isEvenMatrix; i++) {
if(subtractMatchingKeyValuesArr(subtractedFlowers, &(charsPerRow[SideLength-(i+1)], charsPerRow[i])) == -1)
break;
if (!intListContains(blackListedRowsYdirection, i) && !intListContains(blackListedRowsYdirection, SideLength - (i+1))) {
possibleFoundBoxes++;
}
}
//std::cout << " y -><-" << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
subtractedFlowers = uniqueFlowers;
for (int i = 0; i < SideLength/2 - isEvenMatrix; i++) {
if(subtractMatchingKeyValuesArr(subtractedFlowers, &(charsPerRow[SideLength-(i+1)], charsPerColumn[SideLength-(i+1)], charsPerColumn[i])) == -1)
break;
if (!intListContains(blackListedRowsYdirection, i) && !intListContains(blackListedRowsYdirection, SideLength - (i+1)) &&!intListContains(blackListedRowsXdirection, i) && !intListContains(blackListedRowsXdirection, SideLength - (i+1)))
possibleFoundBoxes++;
else break;
}
//std::cout << " xy -><-" << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
subtractedFlowers = uniqueFlowers;
bool foundAll = false;
for(int j = 0; j < SideLength; j++){
for (int i = 0; i < SideLength - j; i++) {
for(int m = 0; m <= i; m++){
if(subtractUniqueFlowersCustomListModifyByRangeY(SideLength-(i+1)-m,i,SideLength-(j+1), subtractedFlowers, niitty) == -1 || subtractUniqueFlowersCustomListModifyByRangeX(i, i, SideLength-(j+1),subtractedFlowers, niitty) == -1){
//std::cout<<i-m << " : "<< j << " : " << i << " : " << m << " : " << SideLength-(j+1) <<endl;
foundAll = true;
break;
}
else{
//std::cout<<i-m << " : "<< j << " : " << i << " : " << m << " : " << SideLength-j <<endl;
//std::cout<<SideLength-i-m<<"!!!"<<endl;
possibleFoundBoxes++;
}
}
if(foundAll)
break;
}
if(foundAll)
break;
}
//std::cout << " yx +-" << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
subtractedFlowers = uniqueFlowers;
foundAll = false;
for(int j = 0; j < SideLength; j++){
for(int m = 0; m < SideLength-(j+1); m++){
for (int i = 0; i < SideLength - j; i++) {
if(subtractUniqueFlowersCustomListModifyByRangeY(i+m, i, SideLength-(j+1), subtractedFlowers, niitty) == -1 || subtractUniqueFlowersCustomListModifyByRangeX(SideLength - (i+1), i, SideLength-(j+1), subtractedFlowers, niitty)==-1){
foundAll = true;
break;
//std::cout<<i-m << " : "<< j << " : " << i << " : " << m << " : " << SideLength-(i+1)-j <<endl;
}
else
possibleFoundBoxes++;
}
if(foundAll)
break;
}
if(foundAll)
break;
}
//std::cout << " yx -+ " << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
subtractedFlowers = uniqueFlowers;
foundAll = false;
for (int j = 0; j < SideLength; j++){
//std::cout<<"uhuh"<<endl;
for(int m = 0; m < SideLength-(j+1); m++){
for (int i = 0; i < SideLength - j; i++) {
//std::cout << i << " : " <<SideLength-(i+1)-j<<endl;
if(subtractUniqueFlowersCustomListModifyByRangeY(i, i, SideLength-(j+1), subtractedFlowers, niitty) == -1 || subtractUniqueFlowersCustomListModifyByRangeX(i+m, i, SideLength - (j+1), subtractedFlowers, niitty) == -1 ){
foundAll = true;
break;
}
else{
possibleFoundBoxes++;
//std::cout<<i-m << " : "<< j << " : " << i << " : " << m << " : " << SideLength-(i+1)-j <<endl;
}
}
if(foundAll)
break;
}
if(foundAll)
break;
}
//std::cout << " xy +-" << possibleFoundBoxes << endl;
//possibleFoundBoxes = 0;
subtractedFlowers = uniqueFlowers;
foundAll = false;
for(int j = 0; j < SideLength; j++){
if(foundAll)
break;
for (int m = 0; m < SideLength-(j+1); m++){
for (int i = 0; i < SideLength - j; i++) {
if(subtractUniqueFlowersCustomListModifyByRangeY(SideLength - (i+1), i, SideLength-(j+1), subtractedFlowers, niitty) == -1 || subtractUniqueFlowersCustomListModifyByRangeX(SideLength - (i+1) - m, i, SideLength-(j+1), subtractedFlowers, niitty)==-1){
foundAll = true;
break;
}
else
possibleFoundBoxes++;
/*
std::cout<<!intListContains(blackListedRowsXdirection, SideLength - (i+1)-m) << " : " << !intListContains(blackListedRowsYdirection, SideLength - (i+1))<<endl;
if (!intListContains(blackListedRowsXdirection, SideLength - (i+1)) && !intListContains(blackListedRowsYdirection, SideLength - (i+1)-m))
possibleFoundBoxes++;
else {
foundAll = true;
break;
}
*/
}
if(foundAll)
break;
}
}
//std::cout << " xy -+" << possibleFoundBoxes << endl;
/*
for(int i : blackListedRowsXdirection){
std::cout<<"x :"<< i <<endl;
}
for(int i : blackListedRowsYdirection){
std::cout<<"y :"<< i <<endl;
}
*/
std::cout << possibleFoundBoxes << endl;
}

Test details

Test 1

Group: 1, 2, 3, 4, 5, 6

Verdict:

input
10
TNCTNPNTPC
NPPNTNTPTP
NTNTTCNTCT
NPCPNPPNTT
...

correct output
2035

user output
52

Test 2

Group: 1, 2, 3, 4, 5, 6

Verdict: ACCEPTED

input
10
NFWQLWNWYS
DZOQJVXFPJ
CNHXPXMCQD
QRTBVNLTQC
...

correct output
9

user output
9

Test 3

Group: 1, 2, 3, 4, 5, 6

Verdict:

input
10
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
...

correct output
3025

user output
61

Test 4

Group: 1, 2, 3, 4, 5, 6

Verdict:

input
10
FFFFFFFFFF
FFFFFCFFFF
FFFFFFJFFF
FFFFFFFFFF
...

correct output
12

user output
8

Test 5

Group: 1, 2, 3, 4, 5, 6

Verdict: ACCEPTED

input
1
X

correct output
1

user output
1

Test 6

Group: 2, 3, 4, 5, 6

Verdict:

input
20
BBCBUBOUOBBCUUBBCOUO
BOUCOOCUBCOOOCOBOCUO
UCCUUUOBCOCBCBUBUCOO
BUOBUCUCUOOBCOOUBUOO
...

correct output
38724

user output
112

Test 7

Group: 2, 3, 4, 5, 6

Verdict:

input
20
CBGLSHGZHYZDWBNDBJUG
SMUXOJQYPXZDTMJUIWOJ
XIDSTNBGHKRKOVUVMINB
MTQGCFRUHQKALXRNCQGS
...

correct output
8334

user output
78

Test 8

Group: 2, 3, 4, 5, 6

Verdict:

input
20
KKKKKKKKKKKKKKKKKKKK
KKKKKKKKKKKKKKKKKKKK
KKKKKKKKKKKKKKKKKKKK
KKKKKKKKKKKKKKKKKKKK
...

correct output
44100

user output
119

Test 9

Group: 2, 3, 4, 5, 6

Verdict:

input
20
AAAAAAAAXAAAAAAAAAAA
AAAWAAAAAAAAAAAAAOAA
AAAAAAAAAAAAAAAAAPAA
AAAAAAAAKAAAAAAAAAAZ
...

correct output
18

user output
13

Test 10

Group: 3, 4, 5, 6

Verdict:

input
50
GRGREEEGREGXRXXEGXXREXGRRRGRRR...

correct output
1584665

user output
292

Test 11

Group: 3, 4, 5, 6

Verdict:

input
50
AITIISJUHCCRZNKSDCNQKYSQRINFWJ...

correct output
1077746

user output
249

Test 12

Group: 3, 4, 5, 6

Verdict:

input
50
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO...

correct output
1625625

user output
306

Test 13

Group: 3, 4, 5, 6

Verdict:

input
50
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

correct output
1680

user output
59

Test 14

Group: 4, 5, 6

Verdict:

input
100
NNCMDCDDCCNNNDNCMMNCDCDCCDCDNM...

correct output
25325366

user output
584

Test 15

Group: 4, 5, 6

Verdict:

input
100
LIMQQIHASECROEVILNVULGWZJPPKOG...

correct output
22342463

user output
538

Test 16

Group: 4, 5, 6

Verdict:

input
100
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...

correct output
25502500

user output
610

Test 17

Group: 4, 5, 6

Verdict:

input
100
QXQQQQQQQQQQQQQQQQQQQQQQQQQQQQ...

correct output
25650

user output
118

Test 18

Group: 5, 6

Verdict:

input
200
NAANANMMKNKKAKMKMAKNKMNKMMNNAA...

correct output
403292767

user output
1205

Test 19

Group: 5, 6

Verdict:

input
200
OMYWATTLURKQPTKEFMGGYAOONXWVSC...

correct output
388111321

user output
1134

Test 20

Group: 5, 6

Verdict:

input
200
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC...

correct output
404010000

user output
1217

Test 21

Group: 5, 6

Verdict:

input
200
LLLLLLLLLLLLLLLLLHLLLLLLLLLLLL...

correct output
14159445

user output
561

Test 22

Group: 6

Verdict:

input
500
VVHWVUHVHUWWWVUUUWVUUHUUWHWUVW...

correct output
15683003812

user output
2981

Test 23

Group: 6

Verdict:

input
500
OIMZGEQSBMBDSDXSWRFNKSGFEBBTJE...

correct output
15575906951

user output
2894

Test 24

Group: 6

Verdict:

input
500
IIIIIIIIIIIIIIIIIIIIIIIIIIIIII...

correct output
15687562500

user output
3032

Test 25

Group: 6

Verdict:

input
500
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW...

correct output
3058970930

user output
1888