805A - Fake NP - CodeForces Solution


greedy math *1000

Please click on ads to support us..

Python Code:

import math
from re import L
import sys,bisect
from collections import deque,OrderedDict,defaultdict
import heapq
from collections import Counter
def inp(): return sys.stdin.readline().rstrip()
def mpp(): return map(int,inp().split())
def lis(): return list(mpp())
def yn(n):
    if n:
        return "YES"
    else:
        return "NO"
def rt(i,n):
    return 0<=i<n
def fn(arr,n,m):
    for i in range(n):
        for j in range(m):
            if arr[i][j]=="S":
                if rt(i-1,n):
                    if arr[i-1][j]!="W" and arr[i-1][j]!="S":
                        arr[i-1][j]="D"
                    elif arr[i-1][j]=="W":
                        print("NO")
                        return
                if rt(i+1,n) :
                    if arr[i+1][j]!="W" and arr[i+1][j]!="S":
                        arr[i+1][j]="D"
                    elif arr[i+1][j]=="W":
                        print("NO")
                        return
                if rt(j-1,m) :
                    if arr[i][j-1]!="W" and  arr[i][j-1]!="S":
                        arr[i][j-1]="D"
                    elif arr[i][j-1]=="W":
                        print("NO")
                        return
                if rt(j+1,m):
                    if arr[i][j+1]!="W" and arr[i][j+1]!="S":
                        arr[i][j+1]="D"
                    elif arr[i][j+1]=="W":
                        print("NO")
                        return
    print("YES")
    for i in range(n):
        print("".join(arr[i]))
    return
            
def main():
    n,m=mpp()
    if n==m:
        print(n)
    else:
        print(2)


            
        
        
            
                
                
                
    
if __name__=="__main__":
    main()

C++ Code:

// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	long long l, n;
	cin>>l>>n;
	if(l==n){
		cout<<l<<'\n';
	}else{
	    cout<<2<<'\n';
	}
}


Comments

Submit
0 Comments
More Questions

1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols