priyansh_max's blog

By priyansh_max, history, 4 days ago, In English

public static void main(String[] args) { FastReader sc = new FastReader();

int t = sc.nextInt();

    for (int i = 0; i < t; i++) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x = sc.nextInt();
        int ans = 0;
        int flag = 0;
        List<Integer> list = new ArrayList<>();
        if((n%2 == 1 && k == 2 && x == 1) || (k == 1 && x == 1)){
            flag = 1;
        }

        else{
            while(k > 0 && n > 0){
                if(k == x){
                    k--;
                }
                else{
                    ans += n/k;
                    int temp = n/k;
                    for(int j = 0; j < temp ; j++){
                        list.add(k);
                    }
                    n = n%k;
                    k--;
                }
            }
        }

        if(flag == 1){
            System.out.println("NO");
        }
        else{
            System.out.println("YES");
            System.out.println(ans);
            for(int j = 0 ; j < list.size() ; j++){
                System.out.print(list.get(j) + " ");
            }
            System.out.println("");
        }
    }
}

I am missing something here It passes all the sample test cases https://codeforces.net/contest/1845/problem/A

please suggest improvement as well :)

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it

By priyansh_max, history, 2 months ago, In English

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

Full text and comments »

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