atcoder_official's blog

By atcoder_official, history, 11 months ago, In English

We will hold AtCoder Beginner Contest 407.

We are looking forward to your participation!

  • Vote: I like it
  • +23
  • Vote: I do not like it

»
11 months ago, hide # |
 
Vote: I like it -46 Vote: I do not like it

qp.

»
11 months ago, hide # |
 
Vote: I like it -15 Vote: I do not like it

Best wishes to everyone RP++.

»
11 months ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

qpzc

»
11 months ago, hide # |
 
Vote: I like it -42 Vote: I do not like it

In the fourth problem ,I didn't get scores for two testing points. who can help me? i will subscrible you.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Terrible contest.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, I'm beginner. Could anyone tell me which test case in problem C I might have missed?

My code :

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int toNumber(char c ){
	return ((int) c - '0');
}

int main(){
	string str; cin >> str;

	ll ans = str.size();

	for(int i = 1; i < str.size(); i++){
		int c1 = toNumber(str[i-1]);
		int c2 = toNumber(str[i]);
		if(c1 > c2){
			ans += c1;
		}else if(c1 < c2){
			ans += 10 - c2;
			ans += c2;
		}
	}

	cout << ans << endl;
}
»
11 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Can anyone please help me out? My solution is failing on 1 testcase.

My approach was:

  • Generate masks of the grid on whether a cell is covered by a domino or not.
  • Iterate thru each row of the grid.
  • For every segment of covered cells in the current row:
    • If the length of the segment is even, do nothing.
    • Else try to place a vertical domino at the first or last covered cell of the segment.
  • Check if there exists a valid placement of dominos according to the mask. If there is, calculate xor value of uncovered cells and take max over all valid masks.
»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

WHICH CASE DID IT WRONG IN. IT PASSED 11 CASSES, 1 TLE 5 REs. Why is it wrong ? It worked for all cases given in problem description

s = input()
count = 0 
n = int(s)

#print("count",count)
#print("n",n)

def transform_number(n, y):
    #n = abs(n)
    y = int(y)
    result = ''
    while len(n) >= 1:
        x = n[:-1]
        d = int(n[-1])
        if d < y:
            result = str(d + 10 - y) + result
        else:
            result = str(d - y) + result
        n = x
    #if result and result[0] == '0':
    #    result = '10' + result[1:]
    #print("result",result)
    return result


while len(s) >= 2:
  last_digit = int(s[-1])
  count += last_digit + 1
  #print("count",count)
  #n = transform_number (n//10 , last_digit)
  s = transform_number (s[:-1] , s[-1])
  #print("n",s)

count += int(s) + 1
print(count)
  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Since $$$|S|\le 5\times 10^5$$$, and your function transform_number has a time complexity of $$$O(n^2)$$$ (by string slicing) and you even call it more than once, it'll definitely TLE. Btw, the reason of your RE might be that the interpreter stored all the result strings produced by slicing operations.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

link to complete solution — https://atcoder.jp/contests/abc407/submissions/66133301

for 4th question I checked if the mask formed by a number can be a valid domino placement using this function

so if domino placement looks like


1100 2203 0003

my mask should be 110011010001 I think

bool isValid(int mask) {
    if (validDp[mask] != -1) return validDp[mask];
    int bits = bitcount(mask);
    if (isOdd(bits)) {
        return validDp[mask] = false;
    }
    int pos = __builtin_ctz(mask);

    int r = pos / m;
    int c = pos % m;

    for (auto dir : fourDirections) {
        int x = r + dir[0];
        int y = c + dir[1];
        if (not inGrid(x, y, n, m)) continue;
        int p = m * x + y;
        if (mask & (1 << p)) {
            int nmask = mask ^ (1 << pos) ^ (1 << p);
            if (isValid(nmask)) return validDp[mask] = true;;
        }
    }

    return validDp[mask] = false;;
}

basically I am checking last set bit of a mask and removing that bit and one of its neighbor ( pos and p ) and remaining mask will be smaller so that can be checked with a DP

I suspect this logic might be wrong as other parts of my solution seem simple, but I am getting almost all WAs :P .. can someone help please

  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    nothing wrong with my logic... i am reading 32-bit integers for array values .. but it should be 64-bit long long values ... yikes man !!!

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think F=MAXI.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can someone please explain E?

  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    First, you know that the first value will always be a '(' and the last value will be ')'. Then at no point in the sequence can the count of ')' be greater than the count of '(' otherwise no matter which numbers you choose there will be a valid construction. So you can find the largest possible by adding the first value to the ans, then looping through the middle section and pushing the values to a priority queue, and every second number (as you need to have at least the same number of '(' as you have')' ) you pop the largest value and add it to your answer.

  • »
    »
    11 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    I think i use a different procedure than edito.

    Build the answer 2 char by 2 char, maintaining a heap of values on ")". Either append () or if there is a ) before and it gives more point to flip it to ( and append )) do that.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone please explain approach to problem D. I saw the constraints were very low and thought of recursion. I thought of generating all possible domino placements and finding the maximum answer. However I was unable to code it out.

  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Your idea is correct.

    Mine
  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You were correct in thinking that. Since you can place a maximum of 10 domino, out of 20 cells in grids. You have three choices for each cell, place type 1 domino, type 2 domino, or keep empty. You can represent the current state of grid using bitmask, each bit representing a grid cell from 1 to 20, and it's occupied status. Keep the visited states in a set, to recalculate earlier states.

  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Bitmask DP, consider your state as int mask

    where mask is nothing but a matrix of dimension H x W which is upto 20 bits so can cache whole grid configuration itself,

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can segtree work for F ? each node contains the answer for the segment, and a prefix max and suffix max of the segment.

I'm unsure of the time complexity.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I understand how to solve E, but still can't solve the D. any things please.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I made a mistake of not initializing one variable in G and got WA on samples. I lost my AK :(

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

does anyone know when's the 408th ABC going to be hold? What I can see now is just the 410th ABC, missing 2 contests btw.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I've got bad luck... I nearly solved C and D...

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone explain E ?

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Good F,greatly better than the one in ABC406 which is a classical ds problem.