Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define lli long long int
#define ld long double
#define pb push_back

ll mod = 1e9 + 7;

ll gcd(ll firstNumber, ll secondNumber) {
if (secondNumber == 0) return firstNumber;
else return gcd(secondNumber, firstNumber % secondNumber);
}


// CODE START

void solveITcaptain() {
int n;
cin>>n;
vector<int> d(n, 0), a(n, 0);
for(int i=0; i<n; i++) {
cin>>d[i];
}

a[0] = d[0];
for(int i=1; i<n; i++) {
int one = a[i-1] + d[i];
int two = a[i-1] - d[i];

if(one != two && one >=0 && two >= 0) {
// cout<<a[i-1]<<" "<<one<<" "<<two<<"\n";
cout<<"-1\n";
return;
}

a[i] = max(one, two);
}

for(int i=0; i<n; i++) {
cout<<a[i]<<" ";
}
cout<<"\n";

}

// CODE END


int main() {
system("cls");
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solveITcaptain();
}
return 0;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define lli long long int
#define ld long double
#define pb push_back

ll mod = 998244353;
// CODE START

ll NCR(ll num, ll re) {
ll p = 1, k = 1;
if (num - re < re)
re = num - re;
if (re != 0) {
while (re) {
p *= num;
k *= re;
long long m = __gcd(p, k);
p /= m;
k /= m;
num--;
re--;
}
}

else
p = 1;
return p;
}

void helper(int i, vector<vector<ll>>& dp) {
if (i == 2) {
return;
}

helper(i - 2, dp);

dp[i][0] = (NCR(i - 1, i / 2) + dp[i - 2][1]) % mod;
dp[i][1] = (NCR(i - 2, i / 2) + dp[i - 2][0]) % mod;
dp[i][2] = (dp[i - 2][2]) % mod;
}

void solveITcaptain() {
int n;
cin >> n;
// Sequence of Turns: Alex Boris Boris Alex Alex Boris Boris Alex
vector<vector<ll>> dp(n + 1, vector<ll>(3, -1));
// Alex Wins
dp[2][0] = 1;
// Boris Wins
dp[2][1] = 0;
// Draw
dp[2][2] = 1;

// helper(n, dp);
for(int i=4; i<=n; i+=2) {
dp[i][0] = (NCR(i - 1, i / 2) + dp[i - 2][1]) % mod;
dp[i][1] = (NCR(i - 2, i / 2) + dp[i - 2][0]) % mod;
dp[i][2] = (dp[i - 2][2]) % mod;
}

cout << dp[n][0] << " " << dp[n][1] << " " << dp[n][2] << "\n";
}

// CODE END


int main() {
system("cls");
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solveITcaptain();
}
return 0;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define lli long long int
#define ld long double
#define pb push_back

ll mod = 1e9 + 7;

ll gcd(ll firstNumber, ll secondNumber) {
if (secondNumber == 0) return firstNumber;
else return gcd(secondNumber, firstNumber % secondNumber);
}


// CODE START

void solveITcaptain() {
int n, m;
cin >> n >> m;

if (n == 1 || m == 1) {
cout << n << " " << m << "\n";
}
else if (n <= 3 && m <= 3) {
cout<<ceil(n/2.0) << " "<< ceil(m/2.0)<<"\n";
}
else {
cout << "1 1\n";
}
}

// CODE END


int main() {
system("cls");
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solveITcaptain();
}
return 0;
}
Binary file not shown.