Code Submission Evaluation System Login

Datatähti 2018 alku

Start:2017-10-02 00:00:00
End:2017-10-16 00:00:00
 

Tasks | Messages | Scoreboard | Statistics


CSES - Datatähti 2018 alku - Results
History
2017-10-12 19:48:53100
2017-10-12 15:57:46100
2017-10-04 18:32:52100
2017-10-04 18:31:5849
2017-10-04 18:30:5349
2017-10-04 18:29:5249
2017-10-04 18:14:3349
2017-10-04 18:11:1449
2017-10-04 18:09:5249
2017-10-04 18:08:0249
2017-10-04 18:07:0949
2017-10-04 18:05:5049
2017-10-04 17:58:4449
2017-10-04 17:57:1949
2017-10-04 17:51:450
2017-10-04 15:10:5222
2017-10-04 12:57:5949
2017-10-04 12:56:1049
2017-10-04 12:54:0549
2017-10-04 12:52:5349
2017-10-04 01:29:197
2017-10-04 01:22:007
2017-10-04 01:19:2034
2017-10-03 23:49:0649
2017-10-03 23:46:070
2017-10-03 23:38:050
2017-10-03 23:22:5049
2017-10-03 23:21:4249
2017-10-03 23:19:4449
2017-10-03 23:18:3922
2017-10-03 22:55:5522
2017-10-03 22:36:2449
2017-10-03 22:35:1949
2017-10-03 22:32:4942
2017-10-03 22:26:1542
2017-10-03 22:10:5342
2017-10-03 22:08:5742
2017-10-03 11:46:2049
2017-10-03 11:42:1622
2017-10-03 11:38:1822
Task:Bittijono
Sender:Yytsi
Submission time:2017-10-12 19:48:53
Language:C++
Status:READY
Score:100

Feedback

groupverdictscore
#1ACCEPTED7
#2ACCEPTED15
#3ACCEPTED27
#4ACCEPTED51

Test results

testverdicttime (s)group
#1ACCEPTED0.04 / 1.001details
#2ACCEPTED0.05 / 1.001details
#3ACCEPTED0.06 / 1.001details
#4ACCEPTED0.06 / 1.001details
#5ACCEPTED0.05 / 1.001details
#6ACCEPTED0.05 / 1.001details
#7ACCEPTED0.07 / 1.001details
#8ACCEPTED0.06 / 1.001details
#9ACCEPTED0.05 / 1.001details
#10ACCEPTED0.05 / 1.001details
#11ACCEPTED0.05 / 1.002details
#12ACCEPTED0.06 / 1.002details
#13ACCEPTED0.05 / 1.002details
#14ACCEPTED0.08 / 1.002details
#15ACCEPTED0.06 / 1.002details
#16ACCEPTED0.08 / 1.002details
#17ACCEPTED0.07 / 1.002details
#18ACCEPTED0.07 / 1.002details
#19ACCEPTED0.07 / 1.002details
#20ACCEPTED0.06 / 1.002details
#21ACCEPTED0.06 / 1.003details
#22ACCEPTED0.13 / 1.003details
#23ACCEPTED0.16 / 1.003details
#24ACCEPTED0.05 / 1.003details
#25ACCEPTED0.06 / 1.003details
#26ACCEPTED0.05 / 1.003details
#27ACCEPTED0.05 / 1.003details
#28ACCEPTED0.18 / 1.003details
#29ACCEPTED0.06 / 1.003details
#30ACCEPTED0.05 / 1.003details
#31ACCEPTED0.34 / 1.004details
#32ACCEPTED0.58 / 1.004details
#33ACCEPTED0.57 / 1.004details
#34ACCEPTED0.48 / 1.004details
#35ACCEPTED0.85 / 1.004details
#36ACCEPTED0.44 / 1.004details
#37ACCEPTED0.66 / 1.004details
#38ACCEPTED0.06 / 1.004details
#39ACCEPTED0.45 / 1.004details
#40ACCEPTED0.08 / 1.004details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:181:25: warning: statement has no effect [-Wunused-value]
     if (res == "fail") 0;//cout << "Length of " << j << " failed!\n";
                         ^
input/code.cpp:163:6: warning: unused variable 'high' [-Wunused-variable]
  int high = len + 2;
      ^

Code

/*
	Written by, Tuukka Yildirim.
	
	input: n.
	
	I blindly followed a false idea that I came up with, which prolonged the
	solving of this problem. Always doubt your ideas that aren't deeply thought ;-)
	
	A binary string of length <s> will have the most unique substrings when filled with
	consecutive ones and zeros. For example, "10101" is the max for <s> = 5.
	Based on this fact, I thought that the shortest binary string <b> with exactly <n> unique
	substrings, will not be found on a region, that has higher amount of maximum unique substrings.
	For example, "10101" contains 19 unique substrings, the highest for <s> = 5. I thought that if
	I were to find the shortest binary string containing 5 unique substrings, it couldn't possibly
	be at <s> = 4 or over, when in fact it could be found at <s> = a high number (in this example,
	it's actually not true, but generally it is).
	
	When I dumped the idea, I constructed a Monte Carlo algorithm to solve the problem.
	Let's call the solution <b>, that is the shortest binary string containing exactly
	<n> unique substrings. NOTE! <b> is not a constant string, but instead many strings
	at the same time (for most of the time).
	
	First, I try to find the solution from the lowest length, from which <b> can be found.
	I do this up to a length of 32 inclusive.
	
	I have a string array <chains> that contain templates to be tested, before shuffling.
	For every length, I take a string <s>, that is one of the strings in <chains> on the
	first 8 iterations, and otherwise a shuffled string based on the modifications done to it.
	I take <s> and start flipping every bit starting from the second bit. At each individual
	flip, I calculate the fitness of <s> with the following formula: abs(distinctSubstrings(s) - n)
	The fitness yields how close it is to the binary string <b>; 0 meaning it's <b>.
	
	After testing, I flip the bit that led to the best fitness (lowest value). I do this, as long as
	the fitness keeps getting better, or the solution gets found. If I encounter a string, that doesn't
	yield any improvement, I shuffle the string with C++'s  std::random_shuffle, that can
	be found at <algorithm>s. I do this almost 21000 times, which seems to be enough.
	NOTE! I never shuffle the first index, nor do I flip it, since it doesn't matter whether the first
	bit is 0 or 1. They are basically the same thing, when you think about it.
	
	A deterministic algorithm I thought about concerned inverting the function that calculates the amount
	of unique substrings a binary string has. However, this seemed easier. Gratz to everyone who solved
	this with a fast and deterministic algorithm! :)
	
	
*/



#include <iostream>
#include <string>
#include <algorithm>

#define T 8

using namespace std;
int n;
string chains[T] = {"101010101010101010101010101010101010101010101",
				   "110100100100010011010010010010010010010010010",
				   "111111111111111111111111111111111111111111111",
				   "100000100001000100100001000010000100001000010",
				   "100010001001011100111110111111011001111101111",
				   "100101000111010010110101001010010100011101001",
				   "110110101100101010101010010111011010110010101",
				   "101011010110100110010011010011010110101101001"};

int bounds[27] = {1, 3, 6, 11, 19, 32, 53, 87, 142, 231, 375, 608, 985, 1595, 2582, 4179,
              6763, 10944, 17709, 28655, 46366, 75023, 121391, 196416, 317809, 514227, 832038};

int numberOfDistinct(const string& str)
{
	int ones = 0;
	int zeros = 0;
	int distinct = 0;
	
	for (size_t i = 0; i < str.length(); i++)
	{
		char bit = str[i];
		bool isOne = bit == '1';
		
		int newSum = 1 + distinct;
		distinct = distinct - (isOne ? ones : zeros) + newSum;
		if (isOne) ones = newSum;
		else zeros = newSum;
	}
	
	return distinct;
}

int binSizeLowerBound(int n)
{
	for (int i = 26; i != 0; i--)
	{
		int bound = bounds[i];
		if (bound < n)
		{
			return i + 1;
		}
	}
	return 1;
}


string findBitstring(string b, int tries)
{
	size_t len = b.size();
	for (int test = 0; test < tries; test++)
	{
		int maxFitness = 123456879, fitIndex = -1;
		while (true)
		{
			bool foundImprovement = false;
			for (size_t i = 1; i < len; i++)
			{
				char bit = b[i];
				char rev = (bit == '1') ? '0' : '1';
				b[i] = rev;
				
				int distinctSubs = numberOfDistinct(b);
				//cout << b << " : " << distinctSubs << "\n";
				
				int fitness = abs(distinctSubs - n);
				if (fitness == 0)
				{
					// Solution found.
					return b;
				}
				if (fitness < maxFitness)
				{
					maxFitness = fitness;
					fitIndex = (int)i;
					foundImprovement = true;
				}
				
				b[i] = bit;
			}
			
			if (foundImprovement) b[fitIndex] = (b[fitIndex] == '1') ? '0' : '1';
			else
			{
				//cout << "No improvement found :-( shuffling\n";
				if (test < T) b = chains[test].substr(0, len);
				else random_shuffle(b.begin() + 1, b.end());
				break;
			}
		}
	}
	return "fail";
}


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	bool found = false;
	string s = "10101010101010101010101010101010101010101010";
	
	
	int len = binSizeLowerBound(n);
	int low = len + 1;
	int high = len + 2;
	
	for (int i = 0; i < 27; i++)
		if (bounds[i] == n) found = true;
	
	bool foundAns = false;
	if (n == 1) cout << "1";
	else if (found) cout << s.substr(0, low);
	else
	{
		for (int i = 0; i < 1; i++)
		{
			string chain = s;
			
			for (int j = low; j < 33; j++)
			{
				string sub = chain.substr(0, j);
				string res = findBitstring(sub, 21000);
				if (res == "fail") 0;//cout << "Length of " << j << " failed!\n";
				else
				{
					// Found an answer....
					cout << res << "\n";
					foundAns = true;
					break;
				}
			}
			
			if (foundAns) break;
		}
	}
	
	return 0;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1
view   save

correct output
1
view   save

user output
1
view   save

Test 2

Group: 1

Verdict: ACCEPTED

input
2
view   save

correct output
11
view   save

user output
11
view   save

Test 3

Group: 1

Verdict: ACCEPTED

input
3
view   save

correct output
10
view   save

user output
10
view   save

Test 4

Group: 1

Verdict: ACCEPTED

input
4
view   save

correct output
1111
view   save

user output
1111
view   save

Test 5

Group: 1

Verdict: ACCEPTED

input
5
view   save

correct output
110
view   save

user output
100
view   save

Test 6

Group: 1

Verdict: ACCEPTED

input
6
view   save

correct output
101
view   save

user output
101
view   save

Test 7

Group: 1

Verdict: ACCEPTED

input
7
view   save

correct output
1110
view   save

user output
1110
view   save

Test 8

Group: 1

Verdict: ACCEPTED

input
8
view   save

correct output
1100
view   save

user output
1100
view   save

Test 9

Group: 1

Verdict: ACCEPTED

input
9
view   save

correct output
1101
view   save

user output
1011
view   save

Test 10

Group: 1

Verdict: ACCEPTED

input
10
view   save

correct output
1001
view   save

user output
1001
view   save

Test 11

Group: 2

Verdict: ACCEPTED

input
38
view   save

correct output
1101011
view   save

user output
1101011
view   save

Test 12

Group: 2

Verdict: ACCEPTED

input
13
view   save

correct output
11011
view   save

user output
11011
view   save

Test 13

Group: 2

Verdict: ACCEPTED

input
90
view   save

correct output
111001010
view   save

user output
101011000
view   save

Test 14

Group: 2

Verdict: ACCEPTED

input
25
view   save

correct output
110010
view   save

user output
110010
view   save

Test 15

Group: 2

Verdict: ACCEPTED

input
82
view   save

correct output
111001101
view   save

user output
101100111
view   save

Test 16

Group: 2

Verdict: ACCEPTED

input
94
view   save

correct output
1100011110
view   save

user output
1100011110
view   save

Test 17

Group: 2

Verdict: ACCEPTED

input
100
view   save

correct output
1111001001
view   save

user output
1111001001
view   save

Test 18

Group: 2

Verdict: ACCEPTED

input
99
view   save

correct output
110010010
view   save

user output
101101100
view   save

Test 19

Group: 2

Verdict: ACCEPTED

input
98
view   save

correct output
110110010
view   save

user output
101000110
view   save

Test 20

Group: 2

Verdict: ACCEPTED

input
92
view   save

correct output
100110001
view   save

user output
100110001
view   save

Test 21

Group: 3

Verdict: ACCEPTED

input
1666
view   save

correct output
101101100100101
view   save

user output
101001001101101
view   save

Test 22

Group: 3

Verdict: ACCEPTED

input
897
view   save

correct output
11101001101010
view   save

user output
11010010111010
view   save

Test 23

Group: 3

Verdict: ACCEPTED

input
4466
view   save

correct output
111101010110100101
view   save

user output
101001001110001011
view   save

Test 24

Group: 3

Verdict: ACCEPTED

input
4240
view   save

correct output
11011001011010101
view   save

user output
11011001011010101
view   save

Test 25

Group: 3

Verdict: ACCEPTED

input
3089
view   save

correct output
1011001010100101
view   save

user output
1010010101001101
view   save

Test 26

Group: 3

Verdict: ACCEPTED

input
4697
view   save

correct output
11010101101010110
view   save

user output
11010101101010110
view   save

Test 27

Group: 3

Verdict: ACCEPTED

input
4608
view   save

correct output
11010110101001010
view   save

user output
11010110101001010
view   save

Test 28

Group: 3

Verdict: ACCEPTED

input
4625
view   save

correct output
111011001100101001
view   save

user output
110110110101011000
view   save

Test 29

Group: 3

Verdict: ACCEPTED

input
4611
view   save

correct output
11010101010101100
view   save

user output
11010100101001010
view   save

Test 30

Group: 3

Verdict: ACCEPTED

input
4917
view   save

correct output
10110100101010110
view   save

user output
10010101011010010
view   save

Test 31

Group: 4

Verdict: ACCEPTED

input
178555
view   save

correct output
1011010110110101010110110
view   save

user output
1001001010101001001010010
view   save

Test 32

Group: 4

Verdict: ACCEPTED

input
864856
view   save

correct output
10111010110110100100101010010
view   save

user output
10110110011010101001110011010
view   save

Test 33

Group: 4

Verdict: ACCEPTED

input
112146
view   save

correct output
1101110101011001100100110
view   save

user output
1100101000101000110100101
view   save

Test 34

Group: 4

Verdict: ACCEPTED

input
741124
view   save

correct output
1011010011010101100101011010
view   save

user output
1011010011010101100101011010
view   save

Test 35

Group: 4

Verdict: ACCEPTED

input
511902
view   save

correct output
1011010100011010100101001110
view   save

user output
1010100100101010100001101001
view   save

Test 36

Group: 4

Verdict: ACCEPTED

input
920019
view   save

correct output
11100100101101010101001101010
view   save

user output
11001011010100101100100101101
view   save

Test 37

Group: 4

Verdict: ACCEPTED

input
933943
view   save

correct output
10101011010100100110100111001
view   save

user output
10011100101100100101011010101
view   save

Test 38

Group: 4

Verdict: ACCEPTED

input
973410
view   save

correct output
1011010101011010101010101001
view   save

user output
1011010101011010101010101001
view   save

Test 39

Group: 4

Verdict: ACCEPTED

input
954943
view   save

correct output
10110110010011010100100110101
view   save

user output
10100100110101010111010010110
view   save

Test 40

Group: 4

Verdict: ACCEPTED

input
911674
view   save

correct output
1010110010110101010101010110
view   save

user output
1010110010110101010101010110
view   save