Submission #645823

# Submission time Handle Problem Language Result Execution time Memory
645823 2022-09-28T06:20:25 Z fatemetmhr Spiral (BOI16_spiral) C++17
27 / 100
1500 ms 296 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb       push_back
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
 
const int maxn5 = 1e5 + 10;
const int inf   = 1e9;
const int mod   = 1e9 + 7;
const ll  mod10 = 10000000070;
 
 
inline ll get(ll x, ll y){
    if(x == 0 && y == 0)
        return 1;
    if(x >= 0 && y < 0){
        if(x == -y)
            return ((2 * x + 1) % mod) * ((2 * x + 1) % mod) % mod;
        if(x < -y)
            return (mod10 + get(-y, y) - (((-y) - x) % mod)) % mod;
        return (get(x - 1, -(x - 1)) + x + y + mod10) % mod;
    }
    if(x < 0 && y <= 0){
        if(x == y)
            return (get(-x, y) + 2 * x + mod10) % mod;
        if(x < y)
            return (get(x, x) - (-x + y) + mod10) % mod;
        return (get(y, y) + (-y + x) + mod10) % mod;
    }
    if(x <= 0 && y > 0){
        if(-x == y)
            return (get(x, x) + 2 * x + mod10) % mod;
        if(-x > y)
            return (get(x, -x) + (-x - y) + mod10) % mod;
        return (get(-y, y) - (y + x) + mod10) % mod;
    }
    if(x > 0 && y >= 0){
        if(x == y)
            return (get(-x, x) - 2 * x + mod10) % mod;
        if(x < y)
            return (get(y, y) + y - x + mod10) % mod;
        return (get(x, x) - (x - y) + mod10) % mod;
    }
    return -1;
}
 
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
    ll n, q; cin >> n >> q;
    while(q--){
        ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        ll ans = 0;
        for(int i = x1; i <= x2; i++) for(int j = y1; j <= y2; j++)
            ans = (ans + get(i, j)) % mod;;
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 666 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 666 ms 296 KB Output is correct
2 Execution timed out 1591 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1598 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 666 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 1591 ms 212 KB Time limit exceeded
4 Halted 0 ms 0 KB -