brute force implementation *1100

Please click on ads to support us..

Python Code:

import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from bisect import bisect_left as bl, bisect_right as br, bisect
from functools import lru_cache
import heapq
import math
from collections import OrderedDict
from collections import Counter
from itertools import combinations
from itertools import accumulate
import operator
import bisect
from collections import deque,defaultdict
import copy
from itertools import permutations
from operator import itemgetter
from functools import lru_cache
import bisect
 
 
BUFSIZE = 8192
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
stdin, stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) 
 
mod = pow(10, 9) + 7
mod2 = 998244353
        
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def ceil(a, b): return (a+b-1)//b
 
def bin(a,b):
    if b==0:
        return 1
    r=bin(a,b//2)
    if b%2:
        return r*r*a
    else:
        return r*r
 
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b % a, a)

def lcm(a,b):
    return (a // gcd(a,b))* b
def check(m,a):
    for i in range(len(a)-1):
        if a[i]+m<a[i+1]:
            return False
    return  True


def solve(d):
    d[0][0]=(d[2][1]+d[1][2])//2
    d[-1][-1]=(d[1][0]+d[0][1])//2
    d[1][1]=(d[0][1]+d[2][1])//2
    for i in range(len(d)):
        for j in range(len(d)):
            print(d[i][j],end=" ")
        print()
'''    
t=iinp()
for i in range(t):
    n=iinp()
        a=lmp()
        solve(n,a)

'''
d=[]
for i in range(3):
    d.append(lmp())
solve(d)

C++ Code:

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

int32_t main() {
    int a00,a01,a02,a10,a11,a12,a20,a21,a22 ;
    cin>>a00>>a01>>a02>>a10>>a11>>a12>>a20>>a21>>a22 ; 
    int sum=(a01+a02+a10+a12+a20+a21)/2 ;
    a00=sum-(a01+a02) ;
    a11=sum-(a10+a12) ;
    a22=sum-(a20+a21) ;
    cout<<a00<<" "<<a01<<" "<<a02<<endl ;
    cout<<a10<<" "<<a11<<" "<<a12<<endl ;
    cout<<a20<<" "<<a21<<" "<<a22<<endl ;
     
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

1385C - Make It Good
651A - Joysticks
1474D - Cleaning
1588A - Two Arrays
816A - Karen and Morning
9D - How many trees
918B - Radio Station
15A - Cottage Village
1737B - Ela's Fitness and the Luxury Number
1425H - Huge Boxes of Animal Toys
1737A - Ela Sorting Books
768C - Jon Snow and his Favourite Number
1006C - Three Parts of the Array
81A - Plug-in
276C - Little Girl and Maximum Sum
1738D - Permutation Addicts
1348B - Phoenix and Beauty
186A - Comparing Strings
1281A - Suffix Three
1421C - Palindromifier
1443A - Kids Seating
963A - Alternating Sum
1191B - Tokitsukaze and Mahjong
1612G - Max Sum Array
1459B - Move and Turn
1006F - Xor-Paths
706C - Hard problem
304C - Lucky Permutation Triple
1301C - Ayoub's function
38E - Let's Go Rolling