| Task: | Niitty | 
| Sender: | DLPS | 
| Submission time: | 2024-10-31 10:48:26 +0200 | 
| Language: | C++ (C++20) | 
| Status: | READY | 
| Result: | 20 | 
| group | verdict | score | 
|---|---|---|
| #1 | ACCEPTED | 4 | 
| #2 | ACCEPTED | 6 | 
| #3 | ACCEPTED | 10 | 
| #4 | TIME LIMIT EXCEEDED | 0 | 
| #5 | TIME LIMIT EXCEEDED | 0 | 
| #6 | TIME LIMIT EXCEEDED | 0 | 
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details | 
| #2 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details | 
| #3 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details | 
| #4 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details | 
| #5 | ACCEPTED | 0.01 s | 1, 2, 3, 4, 5, 6 | details | 
| #6 | ACCEPTED | 0.01 s | 2, 3, 4, 5, 6 | details | 
| #7 | ACCEPTED | 0.01 s | 2, 3, 4, 5, 6 | details | 
| #8 | ACCEPTED | 0.01 s | 2, 3, 4, 5, 6 | details | 
| #9 | ACCEPTED | 0.00 s | 2, 3, 4, 5, 6 | details | 
| #10 | ACCEPTED | 0.06 s | 3, 4, 5, 6 | details | 
| #11 | ACCEPTED | 0.14 s | 3, 4, 5, 6 | details | 
| #12 | ACCEPTED | 0.06 s | 3, 4, 5, 6 | details | 
| #13 | ACCEPTED | 0.00 s | 3, 4, 5, 6 | details | 
| #14 | ACCEPTED | 0.90 s | 4, 5, 6 | details | 
| #15 | TIME LIMIT EXCEEDED | -- | 4, 5, 6 | details | 
| #16 | ACCEPTED | 0.79 s | 4, 5, 6 | details | 
| #17 | ACCEPTED | 0.05 s | 4, 5, 6 | details | 
| #18 | TIME LIMIT EXCEEDED | -- | 5, 6 | details | 
| #19 | TIME LIMIT EXCEEDED | -- | 5, 6 | details | 
| #20 | TIME LIMIT EXCEEDED | -- | 5, 6 | details | 
| #21 | TIME LIMIT EXCEEDED | -- | 5, 6 | details | 
| #22 | TIME LIMIT EXCEEDED | -- | 6 | details | 
| #23 | TIME LIMIT EXCEEDED | -- | 6 | details | 
| #24 | TIME LIMIT EXCEEDED | -- | 6 | details | 
| #25 | TIME LIMIT EXCEEDED | -- | 6 | details | 
Compiler report
input/code.cpp:1:25: warning: extra tokens at end of #include directive
    1 | #include "bits/stdc++.h";
      |                         ^
input/code.cpp:2:25: warning: extra tokens at end of #include directive
    2 | #include "unordered_map";
      |                         ^
input/code.cpp:12:776: warning: integer constant is so large that it is unsigned
   12 | const uint64_t bits[64] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968...Code
#include "bits/stdc++.h";
#include "unordered_map";
using namespace std;
#define byte unsigned char
// Bit masks
//const byte bits[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
//const byte rbits[8] = { 254, 253, 251, 247, 239, 223, 191, 127 };
const uint64_t bits[64] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808 };
const uint64_t rbits[64] = { 18446744073709551614, 18446744073709551613, 18446744073709551611, 18446744073709551607, 18446744073709551599, 18446744073709551583, 18446744073709551551, 18446744073709551487, 18446744073709551359, 18446744073709551103, 18446744073709550591, 18446744073709549567, 18446744073709547519, 18446744073709543423, 18446744073709535231, 18446744073709518847, 18446744073709486079, 18446744073709420543, 18446744073709289471, 18446744073709027327, 18446744073708503039, 18446744073707454463, 18446744073705357311, 18446744073701163007, 18446744073692774399, 18446744073675997183, 18446744073642442751, 18446744073575333887, 18446744073441116159, 18446744073172680703, 18446744072635809791, 18446744071562067967, 18446744069414584319, 18446744065119617023, 18446744056529682431, 18446744039349813247, 18446744004990074879, 18446743936270598143, 18446743798831644671, 18446743523953737727, 18446742974197923839, 18446741874686296063, 18446739675663040511, 18446735277616529407, 18446726481523507199, 18446708889337462783, 18446673704965373951, 18446603336221196287, 18446462598732840959, 18446181123756130303, 18445618173802708991, 18444492273895866367, 18442240474082181119, 18437736874454810623, 18428729675200069631, 18410715276690587647, 18374686479671623679, 18302628885633695743, 18158513697557839871, 17870283321406128127, 17293822569102704639, 16140901064495857663, 13835058055282163711, 9223372036854775807 };
const uint64_t smasks[64] = { 18446744073709551615, 18446744073709551614, 18446744073709551612, 18446744073709551608, 18446744073709551600, 18446744073709551584, 18446744073709551552, 18446744073709551488, 18446744073709551360, 18446744073709551104, 18446744073709550592, 18446744073709549568, 18446744073709547520, 18446744073709543424, 18446744073709535232, 18446744073709518848, 18446744073709486080, 18446744073709420544, 18446744073709289472, 18446744073709027328, 18446744073708503040, 18446744073707454464, 18446744073705357312, 18446744073701163008, 18446744073692774400, 18446744073675997184, 18446744073642442752, 18446744073575333888, 18446744073441116160, 18446744073172680704, 18446744072635809792, 18446744071562067968, 18446744069414584320, 18446744065119617024, 18446744056529682432, 18446744039349813248, 18446744004990074880, 18446743936270598144, 18446743798831644672, 18446743523953737728, 18446742974197923840, 18446741874686296064, 18446739675663040512, 18446735277616529408, 18446726481523507200, 18446708889337462784, 18446673704965373952, 18446603336221196288, 18446462598732840960, 18446181123756130304, 18445618173802708992, 18444492273895866368, 18442240474082181120, 18437736874454810624, 18428729675200069632, 18410715276690587648, 18374686479671623680, 18302628885633695744, 18158513697557839872, 17870283321406128128, 17293822569102704640, 16140901064495857664, 13835058055282163712, 9223372036854775808 };
const uint64_t emasks[64] = { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247, 4503599627370495, 9007199254740991, 18014398509481983, 36028797018963967, 72057594037927935, 144115188075855871, 288230376151711743, 576460752303423487, 1152921504606846975, 2305843009213693951, 4611686018427387903, 9223372036854775807, 18446744073709551615 };
// Debug
int CALLS = 0;
int fieldSize = 0;
struct flowerData
{
	vector<pair<int, int>> positions = vector<pair<int, int>>();
	vector<vector<uint64_t>> rows = vector<vector<uint64_t>>();
	int flowerCount = 0;
	bool init = false;
	void Init()
	{
		if (init)
		{
			return;
		}
		init = true;
		vector<uint64_t> filler(fieldSize / 64 + 1, 0);
		rows.reserve(fieldSize);
		for (int i = 0; i < fieldSize; i++)
		{
			rows.push_back(filler);
		}
	}
	void Insert(int x, int y)
	{
		flowerCount++;
		vector<uint64_t>& row = rows[y];
		// Maybe x - 1
		uint64_t& workingByte = row[ceil(x / 64)];
		// Maybe x - 1
		workingByte |= bits[x % 64];
	}
	bool InBox(int left, int right, int top, int bottom)
	{
		for (int y = top; y <= bottom; y++)
		{
			int minByte = left / 64;
			int minByteStart = left % 64;
			int maxByte = right / 64;
			int maxByteEnd = right % 64;
			if (minByte == maxByte)
			{
				/**/
				uint64_t workingByte = rows[y][minByte];
				
				// Masking from the left
				workingByte &= smasks[minByteStart];
				//for (int i = 0; i < minByteStart; i++)
				//{
				//	workingByte &= rbits[i];
				//}
				// Masking from the right
				workingByte &= emasks[maxByteEnd];
				//for (int i = maxByteEnd + 1; i < 8; i++)
				//{
				//	workingByte &= rbits[i];
				//}
				if (workingByte > 0)
				{
					return true;
				}
			}
			else
			{
				/**/
				uint64_t workingByte = rows[y][minByte];
				// Masking from the left
				workingByte &= smasks[minByteStart];
				//for (int i = 0; i < minByteStart; i++)
				//{
				//	workingByte &= rbits[i];
				//}
				if (workingByte > 0)
				{
					return true;
				}
				for (int i = minByte + 1; i < maxByte; i++)
				{
					if (rows[y][i] > 0)
					{
						return true;
					}
				}
				workingByte = rows[y][maxByte];
				// Masking from the right
				workingByte &= emasks[maxByteEnd];
				//for (int i = maxByteEnd + 1; i < 8; i++)
				//{
				//	workingByte &= rbits[i];
				//}
				if (workingByte > 0)
				{
					return true;
				}
			}
		}
		return false;
	}
};
const unordered_map<char, int> flowerIndecies = { {'A',0},{'B',1},{'C',2},{'D',3},{'E',4},{'F',5},{'G',6},{'H',7},{'I',8},{'J',9},{'K',10},{'L',11},{'M',12},{'N',13},{'O',14},{'P',15},{'Q',16},{'R',17},{'S',18},{'T',19},{'U',20},{'V',21},{'W',22},{'X',23},{'Y',24},{'Z',25} };
vector<flowerData> differentFlowers(26);
bool ContainsAllFlowers(int left, int right, int top, int bottom)
{
	CALLS++;
	for (flowerData& flowerType : differentFlowers)
	{
		if (flowerType.flowerCount <= 0)
		{
			continue;
		}
		if (!flowerType.InBox(left, right, top, bottom))
		{
			return false;
		}
		/*
		// Skip flower types that don't exist.
		if (flowerType.positions.size() <= 0)
		{
			continue;
		}
		bool contains = false;
		for (auto& flower : flowerType.positions)
		{
			if (flower.first < left)
			{
				continue;
			}
			if (flower.first > right)
			{
				continue;
			}
			if (flower.second < top)
			{
				continue;
			}
			if (flower.second > bottom)
			{
				continue;
			}
			contains = true;
			break;
		}
		if (!contains)
		{
			return false;
		}*/
	}
	return true;
}
int main()
{
	cin >> fieldSize;
	cout << "";
	for (int y = 0; y < fieldSize; y++)
	{
		string row;
		cin >> row;
		//map.push_back(move(row));
		for (int x = 0; x < row.size(); x++)
		{
			flowerData& currentFlower = differentFlowers[flowerIndecies.at(row[x])];
			currentFlower.Init();
			//currentFlower.positions.push_back(pair<int, int>(x, y));
			currentFlower.Insert(x, y);
		}
	}
	int count = 0;
	for (int x1 = 0; x1 < fieldSize; x1++)
	{
		bool hadSuccessX2 = false;
		for (int x2 = fieldSize - 1; x2 >= x1; x2--)
		{
			bool hadSuccessY1 = false;
			for (int y1 = 0; y1 < fieldSize; y1++)
			{
				bool hadSuccessY2 = false;
				for (int y2 = fieldSize - 1; y2 >= y1; y2--)
				{
					if (ContainsAllFlowers(x1, x2, y1, y2))
					{
						hadSuccessY2 = true;
						count++;
					}
					else
					{
						break;
					}
				}
				if (!hadSuccessY2)
				{
					break;
				}
				else
				{
					hadSuccessY1 = true;
				}
			}
			if (!hadSuccessY1)
			{
				break;
			}
			else
			{
				hadSuccessX2 = true;
			}
		}
		if (!hadSuccessX2)
		{
			break;
		}
	}
	cout << count;
}Test details
Test 1
Group: 1, 2, 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 10 TNCTNPNTPC NPPNTNTPTP NTNTTCNTCT NPCPNPPNTT ...  | 
| correct output | 
|---|
| 2035 | 
| user output | 
|---|
| 2035 | 
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: ACCEPTED
| input | 
|---|
| 10 XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX ...  | 
| correct output | 
|---|
| 3025 | 
| user output | 
|---|
| 3025 | 
Test 4
Group: 1, 2, 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 10 FFFFFFFFFF FFFFFCFFFF FFFFFFJFFF FFFFFFFFFF ...  | 
| correct output | 
|---|
| 12 | 
| user output | 
|---|
| 12 | 
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: ACCEPTED
| input | 
|---|
| 20 BBCBUBOUOBBCUUBBCOUO BOUCOOCUBCOOOCOBOCUO UCCUUUOBCOCBCBUBUCOO BUOBUCUCUOOBCOOUBUOO ...  | 
| correct output | 
|---|
| 38724 | 
| user output | 
|---|
| 38724 | 
Test 7
Group: 2, 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 20 CBGLSHGZHYZDWBNDBJUG SMUXOJQYPXZDTMJUIWOJ XIDSTNBGHKRKOVUVMINB MTQGCFRUHQKALXRNCQGS ...  | 
| correct output | 
|---|
| 8334 | 
| user output | 
|---|
| 8334 | 
Test 8
Group: 2, 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 20 KKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKK ...  | 
| correct output | 
|---|
| 44100 | 
| user output | 
|---|
| 44100 | 
Test 9
Group: 2, 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 20 AAAAAAAAXAAAAAAAAAAA AAAWAAAAAAAAAAAAAOAA AAAAAAAAAAAAAAAAAPAA AAAAAAAAKAAAAAAAAAAZ ...  | 
| correct output | 
|---|
| 18 | 
| user output | 
|---|
| 18 | 
Test 10
Group: 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 50 GRGREEEGREGXRXXEGXXREXGRRRGRRR...  | 
| correct output | 
|---|
| 1584665 | 
| user output | 
|---|
| 1584665 | 
Test 11
Group: 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 50 AITIISJUHCCRZNKSDCNQKYSQRINFWJ...  | 
| correct output | 
|---|
| 1077746 | 
| user output | 
|---|
| 1077746 | 
Test 12
Group: 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 50 OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO...  | 
| correct output | 
|---|
| 1625625 | 
| user output | 
|---|
| 1625625 | 
Test 13
Group: 3, 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 50 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...  | 
| correct output | 
|---|
| 1680 | 
| user output | 
|---|
| 1680 | 
Test 14
Group: 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 100 NNCMDCDDCCNNNDNCMMNCDCDCCDCDNM...  | 
| correct output | 
|---|
| 25325366 | 
| user output | 
|---|
| 25325366 | 
Test 15
Group: 4, 5, 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 100 LIMQQIHASECROEVILNVULGWZJPPKOG...  | 
| correct output | 
|---|
| 22342463 | 
| user output | 
|---|
| (empty) | 
Test 16
Group: 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 100 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...  | 
| correct output | 
|---|
| 25502500 | 
| user output | 
|---|
| 25502500 | 
Test 17
Group: 4, 5, 6
Verdict: ACCEPTED
| input | 
|---|
| 100 QXQQQQQQQQQQQQQQQQQQQQQQQQQQQQ...  | 
| correct output | 
|---|
| 25650 | 
| user output | 
|---|
| 25650 | 
Test 18
Group: 5, 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 200 NAANANMMKNKKAKMKMAKNKMNKMMNNAA...  | 
| correct output | 
|---|
| 403292767 | 
| user output | 
|---|
| (empty) | 
Test 19
Group: 5, 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 200 OMYWATTLURKQPTKEFMGGYAOONXWVSC...  | 
| correct output | 
|---|
| 388111321 | 
| user output | 
|---|
| (empty) | 
Test 20
Group: 5, 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 200 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC...  | 
| correct output | 
|---|
| 404010000 | 
| user output | 
|---|
| (empty) | 
Test 21
Group: 5, 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 200 LLLLLLLLLLLLLLLLLHLLLLLLLLLLLL...  | 
| correct output | 
|---|
| 14159445 | 
| user output | 
|---|
| (empty) | 
Test 22
Group: 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 500 VVHWVUHVHUWWWVUUUWVUUHUUWHWUVW...  | 
| correct output | 
|---|
| 15683003812 | 
| user output | 
|---|
| (empty) | 
Test 23
Group: 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 500 OIMZGEQSBMBDSDXSWRFNKSGFEBBTJE...  | 
| correct output | 
|---|
| 15575906951 | 
| user output | 
|---|
| (empty) | 
Test 24
Group: 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 500 IIIIIIIIIIIIIIIIIIIIIIIIIIIIII...  | 
| correct output | 
|---|
| 15687562500 | 
| user output | 
|---|
| (empty) | 
Test 25
Group: 6
Verdict: TIME LIMIT EXCEEDED
| input | 
|---|
| 500 WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW...  | 
| correct output | 
|---|
| 3058970930 | 
| user output | 
|---|
| (empty) | 
