eolymp
Problems

New-year tree

published at 8/5/15, 6:08:22 pm

В задаче подразумевается что "рядом" стоят не только любые два элемента с индексами i и i+1, но еще и первый и последний элемент в последовательности стоят тоже "рядом". Об этом не сказано в условии, хотя следовало бы

published at 1/10/17, 1:49:05 pm

test #2 : 1 2 Output:2

published at 7/2/19, 9:06:05 pm

input: 1 10 ..... answer: -1

published at 8/10/19, 4:53:43 pm

EZZZZZZY

published at 2/26/21, 3:28:11 pm

using System;

namespace Problem23 { internal class Program { private static long Addim(long x, long y) { long t = 1; long j = 1; while (j <= y) { t = t*x; j++; } return t; }

    private static long Say(long n, long k)
    {
        if (n == 2) return k*(k - 1);
        return k*Addim(k - 1, n - 1) - Say(n - 1, k);
    }

    private static long Yoxla(long n, long k)
    {
        if (n == 1) return k;
        if ((k == 1) || ((n%2 == 1) && (k == 2))) return -1;
        if ((k == 2) && (n%2 == 0)) return 2;
        return Say(n, k);
    }

    public static void Main(string[] args)
    {
        int say = 0;
        string str = Console.ReadLine();
        var massiv = str.Split(' ');
        int n = int.Parse(massiv[0]);
        int k = int.Parse(massiv[1]);
        Console.WriteLine(Yoxla(n, k));
    }
}

}

published at 8/14/21, 2:45:48 am

Ця задача робиться за допомогою двовимірного ДП, але його можна звести до досить простого одномірного)

published at 9/1/21, 4:25:05 pm

Прислушаюсь

published at 12/10/21, 12:05:46 pm

var k:int64; n:longint; rez:int64;

function step(x, m:int64):int64; var t, j:int64; begin t:=1; j:=1; while j<=m do begin t:=t*x; j:=j+1; end; step:=t; end; function count (n1, k1:int64):int64; begin if n1=2 then count:=k1*(k1-1) else count:=k1*step(k1-1, n1-1)-count(n1-1,k1); end; begin readln (n, k); if n=1 then begin writeln (k); halt; end; if (k=1) or ((n mod 2 =1) and (k=2)) then begin writeln (-1); halt; end; if (k=2) and (n mod 2=0) then begin writeln (2); halt; end; rez:=count(n, k); writeln (rez); end.

published at 6/8/22, 6:06:18 pm

include <bits/stdc++.h>

using namespace std; int main(){ int n,k; cin>>n>>k; cout<<pow(k-1, n-1)*k; return 0; }

WHY 36%?!?

published at 2/2/23, 2:34:55 pm

///░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░░░░ ///░░░░░░░░░░░▄▐░▄▄█████▄▄░░░░░░░░░░░░░░ ///░░░░░░░░░▄█████████████▄▀▄▄░▄▄▄░░░░░░░ ///░░░░░░░░█████████████████▄██████░░░░░░░ ///░░░░░░░████▐█████▌████████▌█████▌░░░░░░░ ///░░░░░░████▌█████▌█░████████▐▀██▀░░░░░░░ ///░░░░▄█████░█████▌░█░▀██████▌█▄▄▀▄░░░░░░░ ///░░░░▌███▌█░▐███▌▌░░▄▄░▌█▌███▐███░▀░░░░░░░ ///░░░▐░▐██░░▄▄▐▀█░░░▐▄█▀▌█▐███▐█░░░░░░░ ///░░░░░███░▌▄█▌░░▀░░▀██░░▀██████▌░░░░░░░ ///░░░░░░▀█▌▀██▀░▄░░░░░░░░░███▐███░░░░░░░░ ///░░░░░░░██▌░░░░░░░░░░░░░▐███████▌░░░░░░░░ ///░░░░░░░███░░░░░▀█▀░░░░░▐██▐███▀▌░░░░░░░░ ///░░░░░░░▌█▌█▄░░░░░░░░░▄▄████▀░▀░░░░░░░ ///░░░░░░░░░█▀██▄▄▄░▄▄▀▀▒█▀█░▀░░░░░░░ ///░░░░░░░░░░░░▀░▀█▀▌▒▒▒░▐▄▄░░░░░░░ ///░░░░░░░░░░░▄▄▀▀▄░░░░░░▄▀░▀▀▄▄░░░░░░░ ///░░░░░░░░░▄▀░▄▀▄░▌░░░▄▀░░░░░░▄▀▀▄░░░░░░░ ///░░░░░░░░▐▒▄▀▄▀░▌▀▄▄▀░░░░░░▄▀▒▒▒▐░░░░░░░ ///░░░░░░░▐▒▒▌▀▄░░░░░▌░░░░▄▄▀▒▐▒▒▒▒▌░░░░░░░ ///░░░░░░▐▒▒▐░▌░▀▄░░▄▀▀▄▀▀▒▌▒▐▒▒▒▒▐▐░░░░░░░░ ///░░░░░░▌▄▀░░░▄▀░█▀▒▒▒▒▀▄▒▌▐▒▒▒▒▒▌▌░░░░░░░ ///░░░░░▄▀▒▐░▄▀░░░▌▒▐▒▐▒▒▒▌▀▒▒▒▒▒▐▒▌░░░░░░

published at 2/8/23, 8:21:51 pm

///░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░░░░ ///░░░░░░░░░░░▄▐░▄▄█████▄▄░░░░░░░░░░░░░░ ///░░░░░░░░░▄█████████████▄▀▄▄░▄▄▄░░░░░░░ ///░░░░░░░░█████████████████▄██████░░░░░░░ ///░░░░░░░████▐█████▌████████▌█████▌░░░░░░░ ///░░░░░░████▌█████▌█░████████▐▀██▀░░░░░░░ ///░░░░▄█████░█████▌░█░▀██████▌█▄▄▀▄░░░░░░░ ///░░░░▌███▌█░▐███▌▌░░▄▄░▌█▌███▐███░▀░░░░░░░ ///░░░▐░▐██░░▄▄▐▀█░░░▐▄█▀▌█▐███▐█░░░░░░░ ///░░░░░███░▌▄█▌░░▀░░▀██░░▀██████▌░░░░░░░ ///░░░░░░▀█▌▀██▀░▄░░░░░░░░░███▐███░░░░░░░░ ///░░░░░░░██▌░░░░░░░░░░░░░▐███████▌░░░░░░░░ ///░░░░░░░███░░░░░▀█▀░░░░░▐██▐███▀▌░░░░░░░░ ///░░░░░░░▌█▌█▄░░░░░░░░░▄▄████▀░▀░░░░░░░ ///░░░░░░░░░█▀██▄▄▄░▄▄▀▀▒█▀█░▀░░░░░░░ ///░░░░░░░░░░░░▀░▀█▀▌▒▒▒░▐▄▄░░░░░░░ ///░░░░░░░░░░░▄▄▀▀▄░░░░░░▄▀░▀▀▄▄░░░░░░░ ///░░░░░░░░░▄▀░▄▀▄░▌░░░▄▀░░░░░░▄▀▀▄░░░░░░░ ///░░░░░░░░▐▒▄▀▄▀░▌▀▄▄▀░░░░░░▄▀▒▒▒▐░░░░░░░ ///░░░░░░░▐▒▒▌▀▄░░░░░▌░░░░▄▄▀▒▐▒▒▒▒▌░░░░░░░ ///░░░░░░▐▒▒▐░▌░▀▄░░▄▀▀▄▀▀▒▌▒▐▒▒▒▒▐▐░░░░░░░░ ///░░░░░░▌▄▀░░░▄▀░█▀▒▒▒▒▀▄▒▌▐▒▒▒▒▒▌▌░░░░░░░ ///░░░░░▄▀▒▐░▄▀░░░▌▒▐▒▐▒▒▒▌▀▒▒▒▒▒▐▒▌░░░░░░

published at 2/8/23, 8:21:54 pm

///░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░░░░ ///░░░░░░░░░░░▄▐░▄▄█████▄▄░░░░░░░░░░░░░░ ///░░░░░░░░░▄█████████████▄▀▄▄░▄▄▄░░░░░░░ ///░░░░░░░░█████████████████▄██████░░░░░░░ ///░░░░░░░████▐█████▌████████▌█████▌░░░░░░░ ///░░░░░░████▌█████▌█░████████▐▀██▀░░░░░░░ ///░░░░▄█████░█████▌░█░▀██████▌█▄▄▀▄░░░░░░░ ///░░░░▌███▌█░▐███▌▌░░▄▄░▌█▌███▐███░▀░░░░░░░ ///░░░▐░▐██░░▄▄▐▀█░░░▐▄█▀▌█▐███▐█░░░░░░░ ///░░░░░███░▌▄█▌░░▀░░▀██░░▀██████▌░░░░░░░ ///░░░░░░▀█▌▀██▀░▄░░░░░░░░░███▐███░░░░░░░░ ///░░░░░░░██▌░░░░░░░░░░░░░▐███████▌░░░░░░░░ ///░░░░░░░███░░░░░▀█▀░░░░░▐██▐███▀▌░░░░░░░░ ///░░░░░░░▌█▌█▄░░░░░░░░░▄▄████▀░▀░░░░░░░ ///░░░░░░░░░█▀██▄▄▄░▄▄▀▀▒█▀█░▀░░░░░░░ ///░░░░░░░░░░░░▀░▀█▀▌▒▒▒░▐▄▄░░░░░░░ ///░░░░░░░░░░░▄▄▀▀▄░░░░░░▄▀░▀▀▄▄░░░░░░░ ///░░░░░░░░░▄▀░▄▀▄░▌░░░▄▀░░░░░░▄▀▀▄░░░░░░░ ///░░░░░░░░▐▒▄▀▄▀░▌▀▄▄▀░░░░░░▄▀▒▒▒▐░░░░░░░ ///░░░░░░░▐▒▒▌▀▄░░░░░▌░░░░▄▄▀▒▐▒▒▒▒▌░░░░░░░ ///░░░░░░▐▒▒▐░▌░▀▄░░▄▀▀▄▀▀▒▌▒▐▒▒▒▒▐▐░░░░░░░░ ///░░░░░░▌▄▀░░░▄▀░█▀▒▒▒▒▀▄▒▌▐▒▒▒▒▒▌▌░░░░░░░ ///░░░░░▄▀▒▐░▄▀░░░▌▒▐▒▐▒▒▒▌▀▒▒▒▒▒▐▒▌░░░░░░

published at 5/17/23, 3:41:58 pm

///░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░░░░ ///░░░░░░░░░░░▄▐░▄▄█████▄▄░░░░░░░░░░░░░░ ///░░░░░░░░░▄█████████████▄▀▄▄░▄▄▄░░░░░░░ ///░░░░░░░░█████████████████▄██████░░░░░░░ ///░░░░░░░████▐█████▌████████▌█████▌░░░░░░░ ///░░░░░░████▌█████▌█░████████▐▀██▀░░░░░░░ ///░░░░▄█████░█████▌░█░▀██████▌█▄▄▀▄░░░░░░░ ///░░░░▌███▌█░▐███▌▌░░▄▄░▌█▌███▐███░▀░░░░░░░ ///░░░▐░▐██░░▄▄▐▀█░░░▐▄█▀▌█▐███▐█░░░░░░░ ///░░░░░███░▌▄█▌░░▀░░▀██░░▀██████▌░░░░░░░ ///░░░░░░▀█▌▀██▀░▄░░░░░░░░░███▐███░░░░░░░░ ///░░░░░░░██▌░░░░░░░░░░░░░▐███████▌░░░░░░░░ ///░░░░░░░███░░░░░▀█▀░░░░░▐██▐███▀▌░░░░░░░░ ///░░░░░░░▌█▌█▄░░░░░░░░░▄▄████▀░▀░░░░░░░ ///░░░░░░░░░█▀██▄▄▄░▄▄▀▀▒█▀█░▀░░░░░░░ ///░░░░░░░░░░░░▀░▀█▀▌▒▒▒░▐▄▄░░░░░░░ ///░░░░░░░░░░░▄▄▀▀▄░░░░░░▄▀░▀▀▄▄░░░░░░░ ///░░░░░░░░░▄▀░▄▀▄░▌░░░▄▀░░░░░░▄▀▀▄░░░░░░░ ///░░░░░░░░▐▒▄▀▄▀░▌▀▄▄▀░░░░░░▄▀▒▒▒▐░░░░░░░ ///░░░░░░░▐▒▒▌▀▄░░░░░▌░░░░▄▄▀▒▐▒▒▒▒▌░░░░░░░ ///░░░░░░▐▒▒▐░▌░▀▄░░▄▀▀▄▀▀▒▌▒▐▒▒▒▒▐▐░░░░░░░░ ///░░░░░░▌▄▀░░░▄▀░█▀▒▒▒▒▀▄▒▌▐▒▒▒▒▒▌▌░░░░░░░ ///░░░░░▄▀▒▐░▄▀░░░▌▒▐▒▐▒▒▒▌▀▒▒▒▒▒▐▒▌░░░░░░

published at 5/17/23, 3:42:18 pm

///░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░░░░ ///░░░░░░░░░░░▄▐░▄▄█████▄▄░░░░░░░░░░░░░░ ///░░░░░░░░░▄█████████████▄▀▄▄░▄▄▄░░░░░░░ ///░░░░░░░░█████████████████▄██████░░░░░░░ ///░░░░░░░████▐█████▌████████▌█████▌░░░░░░░ ///░░░░░░████▌█████▌█░████████▐▀██▀░░░░░░░ ///░░░░▄█████░█████▌░█░▀██████▌█▄▄▀▄░░░░░░░ ///░░░░▌███▌█░▐███▌▌░░▄▄░▌█▌███▐███░▀░░░░░░░ ///░░░▐░▐██░░▄▄▐▀█░░░▐▄█▀▌█▐███▐█░░░░░░░ ///░░░░░███░▌▄█▌░░▀░░▀██░░▀██████▌░░░░░░░ ///░░░░░░▀█▌▀██▀░▄░░░░░░░░░███▐███░░░░░░░░ ///░░░░░░░██▌░░░░░░░░░░░░░▐███████▌░░░░░░░░ ///░░░░░░░███░░░░░▀█▀░░░░░▐██▐███▀▌░░░░░░░░ ///░░░░░░░▌█▌█▄░░░░░░░░░▄▄████▀░▀░░░░░░░ ///░░░░░░░░░█▀██▄▄▄░▄▄▀▀▒█▀█░▀░░░░░░░ ///░░░░░░░░░░░░▀░▀█▀▌▒▒▒░▐▄▄░░░░░░░ ///░░░░░░░░░░░▄▄▀▀▄░░░░░░▄▀░▀▀▄▄░░░░░░░ ///░░░░░░░░░▄▀░▄▀▄░▌░░░▄▀░░░░░░▄▀▀▄░░░░░░░ ///░░░░░░░░▐▒▄▀▄▀░▌▀▄▄▀░░░░░░▄▀▒▒▒▐░░░░░░░ ///░░░░░░░▐▒▒▌▀▄░░░░░▌░░░░▄▄▀▒▐▒▒▒▒▌░░░░░░░ ///░░░░░░▐▒▒▐░▌░▀▄░░▄▀▀▄▀▀▒▌▒▐▒▒▒▒▐▐░░░░░░░░ ///░░░░░░▌▄▀░░░▄▀░█▀▒▒▒▒▀▄▒▌▐▒▒▒▒▒▌▌░░░░░░░ ///░░░░░▄▀▒▐░▄▀░░░▌▒▐▒▐▒▒▒▌▀▒▒▒▒▒▐▒▌░░░░░░

published at 5/18/23, 1:28:04 pm

///░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░░░░ ///░░░░░░░░░░░▄▐░▄▄█████▄▄░░░░░░░░░░░░░░ ///░░░░░░░░░▄█████████████▄▀▄▄░▄▄▄░░░░░░░ ///░░░░░░░░█████████████████▄██████░░░░░░░ ///░░░░░░░████▐█████▌████████▌█████▌░░░░░░░ ///░░░░░░████▌█████▌█░████████▐▀██▀░░░░░░░ ///░░░░▄█████░█████▌░█░▀██████▌█▄▄▀▄░░░░░░░ ///░░░░▌███▌█░▐███▌▌░░▄▄░▌█▌███▐███░▀░░░░░░░ ///░░░▐░▐██░░▄▄▐▀█░░░▐▄█▀▌█▐███▐█░░░░░░░ ///░░░░░███░▌▄█▌░░▀░░▀██░░▀██████▌░░░░░░░ ///░░░░░░▀█▌▀██▀░▄░░░░░░░░░███▐███░░░░░░░░ ///░░░░░░░██▌░░░░░░░░░░░░░▐███████▌░░░░░░░░ ///░░░░░░░███░░░░░▀█▀░░░░░▐██▐███▀▌░░░░░░░░ ///░░░░░░░▌█▌█▄░░░░░░░░░▄▄████▀░▀░░░░░░░ ///░░░░░░░░░█▀██▄▄▄░▄▄▀▀▒█▀█░▀░░░░░░░ ///░░░░░░░░░░░░▀░▀█▀▌▒▒▒░▐▄▄░░░░░░░ ///░░░░░░░░░░░▄▄▀▀▄░░░░░░▄▀░▀▀▄▄░░░░░░░ ///░░░░░░░░░▄▀░▄▀▄░▌░░░▄▀░░░░░░▄▀▀▄░░░░░░░ ///░░░░░░░░▐▒▄▀▄▀░▌▀▄▄▀░░░░░░▄▀▒▒▒▐░░░░░░░ ///░░░░░░░▐▒▒▌▀▄░░░░░▌░░░░▄▄▀▒▐▒▒▒▒▌░░░░░░░ ///░░░░░░▐▒▒▐░▌░▀▄░░▄▀▀▄▀▀▒▌▒▐▒▒▒▒▐▐░░░░░░░░ ///░░░░░░▌▄▀░░░▄▀░█▀▒▒▒▒▀▄▒▌▐▒▒▒▒▒▌▌░░░░░░░ ///░░░░░▄▀▒▐░▄▀░░░▌▒▐▒▐▒▒▒▌▀▒▒▒▒▒▐▒▌░░░░░░

published at 5/18/23, 2:09:49 pm

///░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░░░░ ///░░░░░░░░░░░▄▐░▄▄█████▄▄░░░░░░░░░░░░░░ ///░░░░░░░░░▄█████████████▄▀▄▄░▄▄▄░░░░░░░ ///░░░░░░░░█████████████████▄██████░░░░░░░ ///░░░░░░░████▐█████▌████████▌█████▌░░░░░░░ ///░░░░░░████▌█████▌█░████████▐▀██▀░░░░░░░ ///░░░░▄█████░█████▌░█░▀██████▌█▄▄▀▄░░░░░░░ ///░░░░▌███▌█░▐███▌▌░░▄▄░▌█▌███▐███░▀░░░░░░░ ///░░░▐░▐██░░▄▄▐▀█░░░▐▄█▀▌█▐███▐█░░░░░░░ ///░░░░░███░▌▄█▌░░▀░░▀██░░▀██████▌░░░░░░░ ///░░░░░░▀█▌▀██▀░▄░░░░░░░░░███▐███░░░░░░░░ ///░░░░░░░██▌░░░░░░░░░░░░░▐███████▌░░░░░░░░ ///░░░░░░░███░░░░░▀█▀░░░░░▐██▐███▀▌░░░░░░░░ ///░░░░░░░▌█▌█▄░░░░░░░░░▄▄████▀░▀░░░░░░░ ///░░░░░░░░░█▀██▄▄▄░▄▄▀▀▒█▀█░▀░░░░░░░ ///░░░░░░░░░░░░▀░▀█▀▌▒▒▒░▐▄▄░░░░░░░ ///░░░░░░░░░░░▄▄▀▀▄░░░░░░▄▀░▀▀▄▄░░░░░░░ ///░░░░░░░░░▄▀░▄▀▄░▌░░░▄▀░░░░░░▄▀▀▄░░░░░░░ ///░░░░░░░░▐▒▄▀▄▀░▌▀▄▄▀░░░░░░▄▀▒▒▒▐░░░░░░░ ///░░░░░░░▐▒▒▌▀▄░░░░░▌░░░░▄▄▀▒▐▒▒▒▒▌░░░░░░░ ///░░░░░░▐▒▒▐░▌░▀▄░░▄▀▀▄▀▀▒▌▒▐▒▒▒▒▐▐░░░░░░░░ ///░░░░░░▌▄▀░░░▄▀░█▀▒▒▒▒▀▄▒▌▐▒▒▒▒▒▌▌░░░░░░░ ///░░░░░▄▀▒▐░▄▀░░░▌▒▐▒▐▒▒▒▌▀▒▒▒▒▒▐▒▌░░░░░░

published at 5/18/23, 4:29:25 pm

///░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░░░░ ///░░░░░░░░░░░▄▐░▄▄█████▄▄░░░░░░░░░░░░░░ ///░░░░░░░░░▄█████████████▄▀▄▄░▄▄▄░░░░░░░ ///░░░░░░░░█████████████████▄██████░░░░░░░ ///░░░░░░░████▐█████▌████████▌█████▌░░░░░░░ ///░░░░░░████▌█████▌█░████████▐▀██▀░░░░░░░ ///░░░░▄█████░█████▌░█░▀██████▌█▄▄▀▄░░░░░░░ ///░░░░▌███▌█░▐███▌▌░░▄▄░▌█▌███▐███░▀░░░░░░░ ///░░░▐░▐██░░▄▄▐▀█░░░▐▄█▀▌█▐███▐█░░░░░░░ ///░░░░░███░▌▄█▌░░▀░░▀██░░▀██████▌░░░░░░░ ///░░░░░░▀█▌▀██▀░▄░░░░░░░░░███▐███░░░░░░░░ ///░░░░░░░██▌░░░░░░░░░░░░░▐███████▌░░░░░░░░ ///░░░░░░░███░░░░░▀█▀░░░░░▐██▐███▀▌░░░░░░░░ ///░░░░░░░▌█▌█▄░░░░░░░░░▄▄████▀░▀░░░░░░░ ///░░░░░░░░░█▀██▄▄▄░▄▄▀▀▒█▀█░▀░░░░░░░ ///░░░░░░░░░░░░▀░▀█▀▌▒▒▒░▐▄▄░░░░░░░ ///░░░░░░░░░░░▄▄▀▀▄░░░░░░▄▀░▀▀▄▄░░░░░░░ ///░░░░░░░░░▄▀░▄▀▄░▌░░░▄▀░░░░░░▄▀▀▄░░░░░░░ ///░░░░░░░░▐▒▄▀▄▀░▌▀▄▄▀░░░░░░▄▀▒▒▒▐░░░░░░░ ///░░░░░░░▐▒▒▌▀▄░░░░░▌░░░░▄▄▀▒▐▒▒▒▒▌░░░░░░░ ///░░░░░░▐▒▒▐░▌░▀▄░░▄▀▀▄▀▀▒▌▒▐▒▒▒▒▐▐░░░░░░░░ ///░░░░░░▌▄▀░░░▄▀░█▀▒▒▒▒▀▄▒▌▐▒▒▒▒▒▌▌░░░░░░░ ///░░░░░▄▀▒▐░▄▀░░░▌▒▐▒▐▒▒▒▌▀▒▒▒▒▒▐▒▌░░░░░░