Skip to content

Commit fc0c6fc

Browse files
committed
April long challenge codechef
1 parent e96a8f4 commit fc0c6fc

File tree

12 files changed

+940
-32
lines changed

12 files changed

+940
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include<bits/stdc++.h>
7+
using namespace std;
8+
9+
long long solve()
10+
{
11+
double k1,k2,k3,v;
12+
cin>>k1>>k2>>k3>>v;
13+
cout<<setprecision(10)<<fixed;
14+
cout.precision(2);
15+
v=v*k1*k2*k3;
16+
double req_time=100.0/v;
17+
// cout<<"req_time is "<<req_time<<endl;
18+
if(req_time>=double(9.575))
19+
cout<<"NO"<<endl;
20+
else
21+
cout<<"YES"<<endl;
22+
return 0;
23+
}
24+
25+
int main()
26+
{
27+
// #ifndef ONLINEJUDGE
28+
// freopen("input.txt","r",stdin);
29+
// freopen("output.txt","w",stdout);
30+
// #endif
31+
long long test=1;
32+
cin>>test;
33+
// scanf("%lld",&test);
34+
while(test--)
35+
{
36+
solve();
37+
}
38+
return 0;
39+
}
40+
/* stuff you should look before submission
41+
* int overflow
42+
* special test case (n=0||n=1||n=2)
43+
* don't get stuck on one approach if you get wrong answer
44+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include<bits/stdc++.h>
7+
using namespace std;
8+
typedef long long ll;
9+
10+
// partilly AC
11+
long long solve()
12+
{
13+
ll n,m,k;
14+
cin>>n>>m>>k;
15+
vector<ll> g(n);
16+
for(ll i=0;i<n;i++)
17+
cin>>g[i];
18+
vector<vector<ll>> v(m,vector<ll>(3,0));
19+
vector<ll> ans(1<<n,0);
20+
// 0- ui, 1- vi, 2-di
21+
for(ll i=0;i<m;i++){
22+
for(ll j=0;j<3;j++)
23+
cin>>v[i][j];
24+
v[i][0]--;
25+
v[i][1]--;
26+
}
27+
28+
for(ll i=0;i<(1<<n);i++){
29+
ll sum=0;
30+
vector<bool>check(n,false);
31+
for(ll j=0;j<n;j++){
32+
if(i&(1<<j)){
33+
check[j]=true;
34+
sum+=g[j];
35+
}
36+
}
37+
for(ll j=0;j<m;j++){
38+
ll flag=0;
39+
for(ll k=v[j][0];k<=v[j][1];k++){
40+
if(check[k]==false)
41+
flag=1;
42+
}
43+
if(flag==0)
44+
sum+=v[j][2];
45+
}
46+
47+
ans[i]=sum;
48+
// cout<<"sum is "<<sum<<endl;
49+
}
50+
sort(ans.begin(),ans.end(),greater<ll>());
51+
for(ll i=0;i<k;i++)
52+
cout<<ans[i]<<" ";
53+
cout<<endl;
54+
return 0;
55+
}
56+
57+
int main()
58+
{
59+
// #ifndef ONLINEJUDGE
60+
// freopen("input.txt","r",stdin);
61+
// freopen("output.txt","w",stdout);
62+
// #endif
63+
long long test=1;
64+
cin>>test;
65+
// scanf("%lld",&test);
66+
while(test--)
67+
{
68+
solve();
69+
}
70+
return 0;
71+
}
72+
/* -----------------END OF PROGRAM --------------------*/
73+
/*
74+
* stuff you should look before submission
75+
* constraint and time limit
76+
* int overflow
77+
* special test case (n=0||n=1||n=2)
78+
* don't get stuck on one approach if you get wrong answer
79+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include<bits/stdc++.h>
7+
using namespace std;
8+
typedef long long ll;
9+
10+
11+
// Techniques
12+
// divide into cases, brute force, pattern finding
13+
// sort, greedy, binary search, two pointer
14+
// transform into graph
15+
ll Q,D;
16+
string s;
17+
const ll mini=-(2e18);
18+
const ll maxo=2e18;
19+
20+
// partially solved
21+
long long solve()
22+
{
23+
// cout<<"mini is "<<mini<<endl;
24+
ll start=mini,end=maxo,y_start=mini,y_end=maxo;
25+
ll temp=1;
26+
while(start<=end){
27+
ll mid=(start+end)/2;
28+
if(temp==1){
29+
cout<<temp<<" "<<mid<<" "<<y_start<<endl;
30+
}
31+
else
32+
cout<<temp<<" "<<mid<<" "<<y_start<<" "<<mid<<" "<<y_end<<endl;
33+
cin>>s;
34+
char first_char=s[0];
35+
if(first_char=='X')
36+
temp=2;
37+
else if(s=="O")
38+
return 0;
39+
else if(first_char=='N'){
40+
start=mid+1;
41+
}
42+
else if(first_char=='P')
43+
end=mid-1;
44+
}
45+
return 0;
46+
}
47+
48+
int main()
49+
{
50+
// #ifndef ONLINEJUDGE
51+
// freopen("input.txt","r",stdin);
52+
// freopen("output.txt","w",stdout);
53+
// #endif
54+
long long test=1;
55+
cin>>test>>Q>>D;
56+
57+
// scanf("%lld",&test);
58+
while(test--)
59+
{
60+
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
61+
solve();
62+
}
63+
return 0;
64+
}
65+
/* -----------------END OF PROGRAM --------------------*/
66+
/*
67+
* stuff you should look before submission
68+
* constraint and time limit
69+
* int overflow
70+
* special test case (n=0||n=1||n=2)
71+
* don't get stuck on one approach if you get wrong answer
72+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"NO"<<endl;
26+
#define yes cout<<"YES"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
stringstream pk(s);
60+
ll num;
61+
pk>>num;
62+
return num;
63+
}
64+
65+
string num_to_str(ll num)
66+
{
67+
return to_string(num);
68+
}
69+
// datatype definination
70+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
71+
class Point
72+
{
73+
public:
74+
ll x;
75+
ll y;
76+
ll z;
77+
ll getsum()
78+
{
79+
return x+y+z;
80+
}
81+
};
82+
/* ascii value
83+
A=65,Z=90,a=97,z=122
84+
*/
85+
/* --------------------MAIN PROGRAM----------------------------*/
86+
// to run ctrl+b
87+
const ll INF=LONG_MAX;
88+
const ll mod2=998244353;
89+
90+
ll solve()
91+
{
92+
ll n,m,k;
93+
cin>>n>>m>>k;
94+
vector<vector<ll>> matrix(n,vector<ll>(m,0));
95+
for(ll i=0;i<n;i++){
96+
for(ll j=0;j<m;j++){
97+
cin>>matrix[i][j];
98+
}
99+
}
100+
101+
ll count=0;
102+
103+
104+
vector<vector<ll>>pre_sum(n+1,vector<ll>(m+1,0));
105+
106+
pre_sum[1][1]=matrix[0][0];
107+
108+
for(ll i=1;i<m;i++)
109+
pre_sum[1][i+1]=pre_sum[1][i]+matrix[0][i];
110+
111+
112+
113+
for(ll i=1;i<n;i++){
114+
pre_sum[i+1][1]=pre_sum[i][1]+matrix[i][0];
115+
}
116+
117+
for(ll i=1;i<n;i++){
118+
for(ll j=1;j<m;j++){
119+
pre_sum[i+1][j+1]=pre_sum[i+1][j]+pre_sum[i][j+1]-pre_sum[i][j]+matrix[i][j];
120+
}
121+
}
122+
123+
124+
ll mini=min(n,m);
125+
ll maxo=max(n,m);
126+
count=n*m;
127+
ll temp=2;
128+
while(temp<=mini){
129+
count+=(mini-temp+1)*(maxo-temp+1);
130+
temp++;
131+
}
132+
for(ll i=1;i<=mini;i++){
133+
for(ll j=i;j<=n;j++){
134+
for(ll z=i;z<=m;z++){
135+
ll sum=pre_sum[j][z]+pre_sum[j-i][z-i]-(pre_sum[j-i][z]+pre_sum[j][z-i]);
136+
if(sum<(i*i*k))
137+
count--;
138+
}
139+
}
140+
}
141+
142+
143+
// for(ll i=0;i<=n;i++){
144+
// for(ll j=0;j<=m;j++){
145+
// cout<<pre_sum[i][j]<<" ";
146+
// }
147+
// line;
148+
// }
149+
150+
cout<<count<<endl;
151+
return 0;
152+
}
153+
154+
int main()
155+
{
156+
speed;
157+
/* #ifndef ONLINE_JUDGE
158+
freopen("input.txt","r",stdin);
159+
freopen("output.txt","w",stdout);
160+
#endif */
161+
ll TestCase=1;
162+
cin>>TestCase;
163+
while(TestCase--)
164+
{
165+
solve();
166+
}
167+
}
168+
/* -----------------END OF PROGRAM --------------------*/
169+
/*
170+
* stuff you should look before submission
171+
* constraint and time limit
172+
* int overflow
173+
* special test case (n=0||n=1||n=2)
174+
* don't get stuck on one approach if you get wrong answer
175+
*/

0 commit comments

Comments
 (0)