Блог пользователя atcoder_official

Автор atcoder_official, история, 17 месяцев назад, По-английски

We will hold AtCoder Beginner Contest 407.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +23
  • Проголосовать: не нравится

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится -42 Проголосовать: не нравится

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

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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;
}
»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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.
»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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)
  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think F=MAXI.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can someone please explain E?

  • »
    »
    17 месяцев назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Your idea is correct.

    Mine
»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain E ?