Open TakefumiYamamura opened 7 years ago
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
We have a rectangular parallelepiped of size A×B×C, built with blocks of size 1×1×1. Snuke will paint each of the A×B×C blocks either red or blue, so that:
There is at least one red block and at least one blue block. The union of all red blocks forms a rectangular parallelepiped. The union of all blue blocks forms a rectangular parallelepiped. Snuke wants to minimize the difference between the number of red blocks and the number of blue blocks. Find the minimum possible difference.
2≤A,B,C≤109
#include <iostream>
using namespace std;
long long min(long long a, long long b){
if(a > b){
return b;
}else{
return a;
}
}
int main(){
long long a, b, c;
cin >> a >> b >> c ;
if(a%2 == 0 || b%2 == 0 || c%2 == 0){
cout << 0 << endl;
return 0;
}
long long ans = min(a*b, min(b*c, c*a));
cout << ans << endl;
}
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come in N colors. Those colors are conveniently numbered 1 through N. Snuke currently has no slime. His objective is to have slimes of all the colors together.
Snuke can perform the following two actions:
Select a color i (1≤i≤N), such that he does not currently have a slime in color i, and catch a slime in color i. This action takes him ai seconds.
Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color i (1≤i≤N−1) will become color i+1, and the color of a slime in color N will become color 1. This action takes him x seconds.
Find the minimum time that Snuke needs to have slimes in all N colors.
2≤N≤2,000 ai are integers. 1≤ai≤109 x is an integer. 1≤x≤109
#include <iostream>
#include <algorithm>
#define ll long long
#define INF 1LL << 60
using namespace std;
int N;
ll x;
int a[2010];
int b[2010];
int main(){
cin >> N >> x;
for (int i = 0; i < N; ++i)
{
cin >> a[i];
b[i] = a[i];
}
ll ans = INF;
for (int k = 0; k < N; ++k)
{
ll tmp = k * x;
for (int i = 0; i < N; ++i)
{
b[i] = min(b[i], a[(i - k + N) % N]);
tmp += b[i];
}
ans = min(ans, tmp);
}
cout << ans << endl;
return 0;
}
http://agc004.contest.atcoder.jp/