# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1258590 | phtung | Modsum (NOI12_modsum) | C++20 | 198 ms | 6552 KiB |
#include <bits/stdc++.h>
using namespace std;
#define name "IO"
#define int long long
const int mod = 5;
const int inf = 1e18 + 7;
const int maxn = 1005;
int n;
int Pow(int x, int y)
{
int ans = 1;
while (y > 0)
{
if (y & 1) ans = (ans * x) % mod;
y /= 2;
x = x * x;
x %= mod;
}
return ans;
}
bool cmp(pair<int,int>a, pair<int,int>b)
{
return a.second > b.second;
}
void solve()
{
int n;
cin >> n;
vector<pair<int,int>> a;
for(int i = 1; i <= n; i++)
{
int v, w;
cin >> v >> w;
a.push_back({v, w});
}
vector<pair<int,int>> v;
v.push_back({0, 0});
for(int i = 0; i < n; i++)
{
int sz = v.size();
vector<pair<int, int>> new_v;
for(int j = 0; j < sz; j++)
{
auto [val, cnt] = v[j];
auto [l, r] = a[i];
for(int k = l; k <= r; k++)
{
new_v.push_back({val + k, cnt + 1});
}
}
v.clear();
v = new_v;
}
map<int, int> mp;
for(int i = 0; i < v.size(); i++)
{
auto [val, cnt] = v[i];
mp[val]++;
}
int res = 0;
for(auto [val, cnt] : mp)
{
int sqr = (val % 5) * (val % 5) % 5;
int x = ((sqr * (sqr + 2)) % 5) + 1;
x *= cnt;
res += x;
}
cout << res << "\n";
}
signed main()
{
if (fopen (name".INP", "r"))
{
freopen (name".INP", "r", stdin);
freopen (name".OUT", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
int t = 1;
while(t--) solve();
std::cerr << "Time: " << clock() - start << "ms\n";
return 0;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |