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

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

I am a bit confused here what's the difference? given--> (1 ≤ n ≤ 10^18)

Approach — 1 long min = n/6+(n % 6 > 0 ? 1 : 0);

Approach — 2 long min = (long)Math.ceil((n * 1.0)/6);

Approach — 1 passed all the test cases

Approach — 2 failed on large values of n

Полный текст и комментарии »

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

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

I tried so many combinations and permutations of what could be answer the description does not help me much and the solutions does not help me understand why is that working...

Can somebody help me? problem link --> https://mirror.codeforces.com/contest/2095/problem/B

Полный текст и комментарии »

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

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

long t = sc.nextLong();

while (t-- > 0) {
        long n = sc.nextLong();
        int[][] grid = new int[2][(int) (n + 3)];

        long ans = 0;
        for(int i = 0 ; i < n ; i++){
            int v1 = sc.nextInt();
            int v2 = sc.nextInt();

            grid[v2][v1]++;
        }

        for(int i = 0 ; i <= n ; i++){
            if(grid[0][i] > 0 && grid[1][i] > 0){
                ans += (n-2);
            }
        }

        for(int i = 0 ; i <= n ; i++){
            if(grid[0][i] > 0 && i > 0 && i < n-1){
                if(grid[1][i-1] > 0 && grid[1][i+1] > 0){
                    ans += 1;
                }
            }
        }


        for(int i = 0 ; i <= n ; i++){
            if(grid[1][i] != 0 && i > 0 && i < n-1){
                if(grid[0][i-1] != 0 && grid[0][i+1] != 0){
                    ans += 1;
                }
            }
        }

        System.out.println(ans);

    }
}

This is my logic I cant figure out which case am i missing

Полный текст и комментарии »

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