# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1279348 | longlong5a6 | Fortune Telling 2 (JOI14_fortune_telling2) | C++20 | 3094 ms | 1236 KiB |
//longlong5a6
#include <bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define bit(i, x)((x >> i) & 1)
#define sobit(i) __builtin_popcount((int)(i))
#define sobitll(i) __builtin_popcountll((int)(i))
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define For(i,x,n) for(int (i)=(int)(x);(i)<=(int)(n);(i)++)
#define round(m,n) setprecision((int)m) << fixed << double(n)
#define down "\n"
#define TASK "domino"
#define int long long
#define maxn 200001
using namespace std;
int n,k;
pii a[maxn];
int t[maxn];
int global;
pii calc(int l,int r)
{
if (l==r)
{
int res1,res2;
res1=0;
res2=1;
if (t[l]>=a[global].F) res1=1;
if (t[l]>=a[global].S) res2=0;
return {res1,res2};
}
int mid=(r+l)/2;
pii left=calc(l,mid);
pii right=calc(mid+1,r);
int res1,res2;
res1=res2=0;
if (left.F&1)
{
res1=right.S;
}
else
{
res1=right.F;
}
if (left.S&1)
{
res2=right.S;
}
else
{
res2=right.F;
}
return {res1,res2};
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("in.txt","r"))
{
freopen("in.txt","r",stdin);
}
if (fopen(TASK".INP","r"))
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
cin>>n>>k;
For(i,1,n)
{
cin>>a[i].F>>a[i].S;
}
For(i,1,k)
{
cin>>t[i];
}
int res=0;
For(i,1,n)
{
global=i;
pii g=calc(1,k);
if (g.F&1) res+=a[i].S;
else res+=a[i].F;
}
cout<<res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |