UVa 394 - Mapmaker
Problem Link: 394 - Mapmaker
/**
* @Author: Pranta Sarker
*
**/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define pfn(x , k) printf(k , x)
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
#define clr clear()
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
typedef map<string, LL>mpsll;
const int mod = 1000007;
const int high = 3e5+3;
struct info
{
string s;
LL B , Cd , D;
LL lower[100], upper[100];
}arr[high];
mpsi visit, par;
LL inputs[high] , C[high];
int main()
{
fast;
LL N , R , i , j;
cin >> N >> R;
for(i=1; i<=N; i++)
{
cin >> arr[i].s >> arr[i].B >> arr[i].Cd >> arr[i].D;
visit[arr[i].s] = 1;
par[arr[i].s] = i;
LL dim = arr[i].D;
for(j=1; j<=dim; j++)
{
cin >> arr[i].lower[j] >> arr[i].upper[j];
}
}
while(R--)
{
string inpstring;
cin >> inpstring;
if(!visit[inpstring]) break;
LL pindx = par[inpstring];
LL dim = arr[pindx].D;
for(i=1; i<=dim; i++)
{
cin >> inputs[i];
}
C[dim] = arr[pindx].Cd;
for(i=dim-1; i>0; i--)
{
LL lwr = arr[pindx].lower[i+1];
LL upr = arr[pindx].upper[i+1];
C[i] = C[i+1] * ( upr - lwr + 1 );
}
C[0] = arr[pindx].B;
for(i=1; i<=dim; i++)
{
LL lwr = arr[pindx].lower[i];
C[0] -= ( C[i] * lwr );
}
LL ans = C[0];
cout << inpstring << "[";
int fl = 0;
for(i=1; i<=dim; i++)
{
ans += ( C[i] * inputs[i] );
if(!fl)
{
cout << inputs[i];
fl = 1;
}
else
{
cout << ", " << inputs[i];
}
}
cout << "] = " << ans << "\n";
}
return 0;
}
【Accepted】
/**
* @Author: Pranta Sarker
*
**/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define pfn(x , k) printf(k , x)
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
#define clr clear()
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
typedef map<string, LL>mpsll;
const int mod = 1000007;
const int high = 3e5+3;
struct info
{
string s;
LL B , Cd , D;
LL lower[100], upper[100];
}arr[high];
mpsi visit, par;
LL inputs[high] , C[high];
int main()
{
fast;
LL N , R , i , j;
cin >> N >> R;
for(i=1; i<=N; i++)
{
cin >> arr[i].s >> arr[i].B >> arr[i].Cd >> arr[i].D;
visit[arr[i].s] = 1;
par[arr[i].s] = i;
LL dim = arr[i].D;
for(j=1; j<=dim; j++)
{
cin >> arr[i].lower[j] >> arr[i].upper[j];
}
}
while(R--)
{
string inpstring;
cin >> inpstring;
if(!visit[inpstring]) break;
LL pindx = par[inpstring];
LL dim = arr[pindx].D;
for(i=1; i<=dim; i++)
{
cin >> inputs[i];
}
C[dim] = arr[pindx].Cd;
for(i=dim-1; i>0; i--)
{
LL lwr = arr[pindx].lower[i+1];
LL upr = arr[pindx].upper[i+1];
C[i] = C[i+1] * ( upr - lwr + 1 );
}
C[0] = arr[pindx].B;
for(i=1; i<=dim; i++)
{
LL lwr = arr[pindx].lower[i];
C[0] -= ( C[i] * lwr );
}
LL ans = C[0];
cout << inpstring << "[";
int fl = 0;
for(i=1; i<=dim; i++)
{
ans += ( C[i] * inputs[i] );
if(!fl)
{
cout << inputs[i];
fl = 1;
}
else
{
cout << ", " << inputs[i];
}
}
cout << "] = " << ans << "\n";
}
return 0;
}
Comments
Post a Comment