답안 #51587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51587 2018-06-18T23:45:17 Z MatheusLealV Martian DNA (IOI16_dna) C++17
100 / 100
18 ms 756 KB
#include "dna.h"

#include <bits/stdc++.h>

using namespace std;

int bsearch1(int n)
{
	int ini = 1, fim = n, mid, best;

	while(fim >= ini)
	{
		mid = (ini + fim)/2;

		string aux;

		for(int i = 1; i <= mid; i++) aux += "0";

		if(make_test(aux)) best = mid, ini = mid + 1;

		else fim = mid - 1;
	}

	return best;
}

string analyse(int n, int t) 
{
    string ans, S, resp;

    int mz = bsearch1(n);

    for(int i = 0; i < mz; i++) ans += "0";

    for(int i = 1; i <= n - mz; i++)
    {
    	if(make_test(ans + "1")) ans += "1";

    	else
    	{
    		int qtdz = 0;

    		for(int j = ans.size() - 1; j >= 0; j--)
    		{
    			if(ans[j] != '0') break;

    			qtdz ++;
    		}

    		if(qtdz > mz) break;

    		ans += "0";
    	}
    }

    int ini = mz - 1, fim = n - 1, mid, best;

    while(fim >= ini)
    {
    	mid = (ini + fim)/2;

    	string aux;

    	for(int i = 0; i <= mid; i++) aux += ans[i];

    	if(make_test(aux)) best = mid, ini = mid + 1;

    	else fim = mid - 1;
    }

    for(int i = 0; i <= best; i++) S += ans[i];

    for(int resta = 1; resta < n - best; resta ++)
    {
    	if(make_test("1" + S)) S = "1" + S;

    	else S = "0" + S;
    }

    return S;
}                       

Compilation message

dna.cpp: In function 'int bsearch1(int)':
dna.cpp:24:9: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
  return best;
         ^~~~
dna.cpp: In function 'std::__cxx11::string analyse(int, int)':
dna.cpp:71:22: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
     for(int i = 0; i <= best; i++) S += ans[i];
                    ~~^~~~~~~
grader.cpp: In function 'bool make_test(std::__cxx11::string)':
grader.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < p.size(); i++) {
                  ~~^~~~~~~~~~
grader.cpp:23:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i <= ss.size(); i++) {
                  ~~^~~~~~~~~~~~
grader.cpp:28:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (pr[i] == p.size()) {
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 2 ms 480 KB Output is correct
8 Correct 2 ms 540 KB Output is correct
9 Correct 2 ms 564 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 652 KB Output is correct
24 Correct 2 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 652 KB Output is correct
2 Correct 2 ms 652 KB Output is correct
3 Correct 2 ms 652 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 2 ms 652 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 3 ms 652 KB Output is correct
9 Correct 2 ms 652 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 652 KB Output is correct
13 Correct 2 ms 652 KB Output is correct
14 Correct 2 ms 652 KB Output is correct
15 Correct 2 ms 652 KB Output is correct
16 Correct 2 ms 652 KB Output is correct
17 Correct 2 ms 652 KB Output is correct
18 Correct 2 ms 652 KB Output is correct
19 Correct 3 ms 652 KB Output is correct
20 Correct 2 ms 652 KB Output is correct
21 Correct 2 ms 652 KB Output is correct
22 Correct 2 ms 652 KB Output is correct
23 Correct 2 ms 652 KB Output is correct
24 Correct 2 ms 652 KB Output is correct
25 Correct 2 ms 652 KB Output is correct
26 Correct 2 ms 652 KB Output is correct
27 Correct 2 ms 652 KB Output is correct
28 Correct 2 ms 652 KB Output is correct
29 Correct 2 ms 652 KB Output is correct
30 Correct 2 ms 652 KB Output is correct
31 Correct 2 ms 652 KB Output is correct
32 Correct 2 ms 652 KB Output is correct
33 Correct 2 ms 652 KB Output is correct
34 Correct 2 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 652 KB Output is correct
2 Correct 2 ms 652 KB Output is correct
3 Correct 2 ms 652 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 2 ms 652 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 652 KB Output is correct
9 Correct 2 ms 652 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 652 KB Output is correct
13 Correct 2 ms 652 KB Output is correct
14 Correct 2 ms 652 KB Output is correct
15 Correct 2 ms 652 KB Output is correct
16 Correct 2 ms 652 KB Output is correct
17 Correct 2 ms 652 KB Output is correct
18 Correct 2 ms 652 KB Output is correct
19 Correct 2 ms 652 KB Output is correct
20 Correct 2 ms 652 KB Output is correct
21 Correct 2 ms 652 KB Output is correct
22 Correct 12 ms 652 KB Output is correct
23 Correct 13 ms 652 KB Output is correct
24 Correct 12 ms 652 KB Output is correct
25 Correct 18 ms 652 KB Output is correct
26 Correct 16 ms 756 KB Output is correct
27 Correct 11 ms 756 KB Output is correct
28 Correct 11 ms 756 KB Output is correct
29 Correct 2 ms 756 KB Output is correct
30 Correct 10 ms 756 KB Output is correct
31 Correct 9 ms 756 KB Output is correct
32 Correct 2 ms 756 KB Output is correct
33 Correct 11 ms 756 KB Output is correct
34 Correct 11 ms 756 KB Output is correct
35 Correct 10 ms 756 KB Output is correct
36 Correct 13 ms 756 KB Output is correct
37 Correct 11 ms 756 KB Output is correct
38 Correct 8 ms 756 KB Output is correct
39 Correct 8 ms 756 KB Output is correct