Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

380C #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

380C #12

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
81 changes: 81 additions & 0 deletions Codeforces/380c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//$ time g++ -c -std=c++11 vec.cpp -fconstexpr-depth=600
//OPT COMPILER:global compiler c++11
//{
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(auto i=0;i<(n);++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(v) v.size()
#define all(v) std::begin(v), std::end(v)
#define vi vector<int>
#define hell 1000000007LL
#define StringToInt(s,n) if ( ! (istringstream(s) >> n) ) n = 0;
#ifdef ONLINE_JUDGE
#define o(x) ;
#else
#define o(x) cerr << #x << " = " << x << endl;
#endif // ONLINE_JUDGE
using namespace std;

ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline int read() {
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
return x*f;
}
//}

int const sq = 7000;
map< pair<int,int> , int > m;
string s;
//memo*****************************************
int f(int a, int b){

auto it=m.find( mp(a,b));
if (it!=m.end()) return it->se;

//cas vide
if (a>=b) return 0;
int mx = 0;
//cas on considere el (/)
if (s[a]=='('){
for(int i=a+1; i<=b;++i){
if (s[i]==')')
mx = max(mx, 2+f(a+1,i-1)+f(i+1,b) );
}
}
// cas na7groha
mx = max(mx, f(a+1,b));


return mx;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("a.txt", "r", stdin);
#endif // ONLINE_JUDGE
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//cout << fixed << setprecision(9);




getline(cin, s);
// cout<<s;

int m,a,b;
cin>>m;
rep(i,m){
cin>>a>>b;
cout<<f(a-1,b-1)<<"\n";
}



return 0;}
126 changes: 126 additions & 0 deletions Codeforces/808D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//$ time g++ -c -std=c++11 vec.cpp -fconstexpr-depth=600
//#pragma comment(linker, "/STACK:36777216")
//OPT COMPILER:global compiler c++11
//Lex MOD-0 ver. 2.3 (19/06/2018)
//la ilaha illallah
//{
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(auto i=0;i<(n);++i)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(v) v.size()
#define all(v) std::begin(v), std::end(v)
#define vi vector<int>
#define mod 1000000007LL

#define StringToInt(s,n) if ( ! (istringstream(s) >> n) ) n = 0;
using namespace std;
template <typename T>
string NumberToString ( T Number )
{
std::ostringstream ss;
ss << Number;
return ss.str();
}

#ifdef ONLINE_JUDGE
#define line
#define o(x)
#else
#define line cerr<<'\n';
#define o(x) cerr << __LINE__ << " $" << #x << " = " << x << "\n";
#endif // ONLINE_JUDGE

ll qpow(ll p,ll q)
{
ll f=1;
while(q) {
if(q&1)
f=f*p%mod;
p=p*p%mod;
q>>=1;
}
return f;
}
inline int read()
{
int x=0,f=1;
char ch=getchar();
while (ch<'0'||ch>'9') {
if (ch=='-')
f=-1;
ch=getchar();
}
while (ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
//}


int const N = 100053;
int n;
ll tab[N];
ll cum[N];
int main()
{
ll tot = 0 ;
#ifndef ONLINE_JUDGE
//n = N-53;
//srand (time(NULL));
//for(int i = 0 ; i<n ; i++){
// tab[i]=rand() ;
// tot+= tab[i];
// cum[i]=tot;
// }

freopen("a.txt","r",stdin);
#else
#endif // ONLINE_JUDGE
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

cin >> n ;
rep(i,n){
cin >> tab[i] ;
tot+= tab[i];
cum[i]=tot;
}

if(tot&1LL || n==1) {
cout<< "NO";
cerr<<1;
return 0;
}
auto chtar = tot/2;
if (binary_search(begin(cum),begin(cum)+n-1,chtar) ) {
cout << "YES";
cerr<<2;
exit(0) ;
}
rep(i,n) {
if ( binary_search(begin(cum)+i,begin(cum)+n,chtar+tab[i]) ) {
cout << "YES";
exit(0) ;
}
}
for(int i=1; i<n;++i) {
if ( binary_search(begin(cum),begin(cum)+i-1,chtar-tab[i]) ) {
cout << "YES";

o(chtar)
o(chtar-tab[i])
o(tab[i])
o(i)
exit(0) ;
}
}
cout<< "NO";
return 0 ;
}