mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
added cses
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
//URL - https://cses.fi/problemset/task/1069
|
||||
//CSES
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbg(x) cerr << #x << " = " << x << endl
|
||||
#else
|
||||
#define dbg(x)
|
||||
#endif
|
||||
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define ar array
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define sza(x) (int)(x).size()
|
||||
|
||||
const ll INF = 1e18;
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
void solve() {
|
||||
string s;
|
||||
cin>>s;
|
||||
int cur = 1, best = 1;
|
||||
|
||||
for(int i =1;i<s.size();i++){
|
||||
|
||||
if(s[i]==s[i-1]) cur++;
|
||||
else cur =1;
|
||||
best = max(best,cur);
|
||||
|
||||
}
|
||||
cout<<best;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
int tc = 1;
|
||||
// cin >> tc;
|
||||
while(tc--) solve();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//URL - https://cses.fi/problemset/task/1070/
|
||||
//CSES
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbg(x) cerr << #x << " = " << x << endl
|
||||
#else
|
||||
#define dbg(x)
|
||||
#endif
|
||||
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define ar array
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define sza(x) (int)(x).size()
|
||||
|
||||
const ll INF = 1e18;
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin>>n;
|
||||
if(n==1) {
|
||||
cout<<n;
|
||||
return;
|
||||
}
|
||||
if(n<4){ cout<<"NO SOLUTION";
|
||||
return;
|
||||
}
|
||||
for(int i =2;i<=n;i+=2)
|
||||
cout<<i<<" ";
|
||||
|
||||
|
||||
|
||||
for(int i = 1;i<=n;i+=2){
|
||||
cout<<i<<" ";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
int tc = 1;
|
||||
// cin >> tc;
|
||||
while(tc--) solve();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//URL -https://cses.fi/problemset/task/1071
|
||||
//CSES
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbg(x) cerr << #x << " = " << x << endl
|
||||
#else
|
||||
#define dbg(x)
|
||||
#endif
|
||||
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define ar array
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define sza(x) (int)(x).size()
|
||||
|
||||
const ll INF = 1e18;
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
void solve() {
|
||||
long long y,x;
|
||||
cin>>y>>x;
|
||||
long long ans = 0;
|
||||
long long n = max(y,x);
|
||||
if(n%2==0){
|
||||
if(y==n){
|
||||
ans = n*n-(x-1);
|
||||
|
||||
}else{
|
||||
ans = (n-1)*(n-1)+y;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(x==n){
|
||||
ans = n*n-(y-1);
|
||||
|
||||
}else{
|
||||
ans = (n-1)*(n-1)+x;
|
||||
}
|
||||
}
|
||||
cout<<ans<<"\n";
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
int tc = 1;
|
||||
cin >> tc;
|
||||
while(tc--) solve();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//URL -
|
||||
//CSES
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbg(x) cerr << #x << " = " << x << endl
|
||||
#else
|
||||
#define dbg(x)
|
||||
#endif
|
||||
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define ar array
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define sza(x) (int)(x).size()
|
||||
|
||||
const ll INF = 1e18;
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
void solve() {
|
||||
long long n;
|
||||
cin>>n;
|
||||
for(long long k = 1;k<=n;k++){
|
||||
long long total = (k*k*(k*k-1))/2;
|
||||
long long attack = 4 *((k-1)*(k-2));
|
||||
cout<<total - attack<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
int tc = 1;
|
||||
// cin >> tc;
|
||||
while(tc--) solve();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//URL - https://cses.fi/problemset/task/1083
|
||||
//CSES
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbg(x) cerr << #x << " = " << x << endl
|
||||
#else
|
||||
#define dbg(x)
|
||||
#endif
|
||||
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define ar array
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define sza(x) (int)(x).size()
|
||||
|
||||
const ll INF = 1e18;
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
void solve() {
|
||||
ll n;
|
||||
cin>>n;
|
||||
ll sum = (n*(n+1))/2;
|
||||
int num;
|
||||
while(cin>>num){
|
||||
sum-=num;
|
||||
|
||||
}
|
||||
cout<<sum;
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
int tc = 1;
|
||||
// cin >> tc;
|
||||
while(tc--) solve();
|
||||
}
|
||||
|
||||
//XOR approach
|
||||
/*
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
ll x = 0;
|
||||
|
||||
for(int i = 1; i <= n; i++)
|
||||
x ^= i;
|
||||
|
||||
for(int i = 0; i < n-1; i++){
|
||||
int a;
|
||||
cin >> a;
|
||||
x ^= a;
|
||||
}
|
||||
|
||||
cout << x << "\n";
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,47 @@
|
||||
//URL - https://cses.fi/problemset/task/1094
|
||||
//CSES
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbg(x) cerr << #x << " = " << x << endl
|
||||
#else
|
||||
#define dbg(x)
|
||||
#endif
|
||||
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define ar array
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define sza(x) (int)(x).size()
|
||||
|
||||
const ll INF = 1e18;
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
void solve() {
|
||||
ll n;
|
||||
cin>>n;
|
||||
vector<ll>s(n);
|
||||
ll count = 0;
|
||||
for(ll i =0;i<n;i++){
|
||||
cin>>s[i];
|
||||
}
|
||||
for(ll i=1;i<n;i++){
|
||||
ll diff = s[i-1] - s[i];
|
||||
if(diff>0) {
|
||||
count+=diff;
|
||||
s[i] = s[i-1];
|
||||
}
|
||||
}
|
||||
cout<<count;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
int tc = 1;
|
||||
// cin >> tc;
|
||||
while(tc--) solve();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user