답안 #51316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51316 2018-06-17T12:55:09 Z mareksom Spiral (BOI16_spiral) C++17
12 / 100
280 ms 387248 KB
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ld = long double;
using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<vector<int>> tab(2 * n + 1, vector<int>(2 * n + 1, -1));
  auto Get = [n, &tab](int r, int c) -> int& {
    assert(-n <= r and r <= n);
    assert(-n <= c and c <= n);
    return tab[r + n][c + n];
  };

  /* Wypełnienie. */ {
    int nast = 1;
    int x = 0, y = 0;
    Get(x, y) = nast++;
    for (int i = 1; i <= n; i++) {
      Get(++x, y) = nast++;
      for (int j = 1; j < i * 2; j++) {
        Get(x, ++y) = nast++;
      }
      for (int j = 0; j < i * 2; j++) {
        Get(--x, y) = nast++;
      }
      for (int j = 0; j < i * 2; j++) {
        Get(x, --y) = nast++;
      }
      for (int j = 0; j < i * 2; j++) {
        Get(++x, y) = nast++;
      }
    }
    #ifdef LOCAL
    for (y = n; y >= -n; y--) {
      debug deb;
      for (x = -n; x <= n; x++) {
        deb << " ";
        int val = Get(x, y);
        vector<int> dig;
        for (int j = 0; j < 3; j++) {
          dig.push_back(val % 10);
          val /= 10;
        }
        bool niezero = false;
        reverse(dig.begin(), dig.end());
        for (int d : dig) {
          if (d == 0 and !niezero) {
            deb << " ";
          } else {
            niezero = true;
            deb << d;
          }
        }
      }
    }
    #endif
  }

  while (q--) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int suma = 0;
    for (int x = x1; x <= x2; x++) {
      for (int y = y1; y <= y2; y++) {
        DodajDo(suma, Get(x, y));
      }
    }
    cout << suma << endl;
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 16120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 16120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 16120 KB Output is correct
2 Runtime error 280 ms 387248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 387248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 16120 KB Output is correct
2 Runtime error 5 ms 16120 KB Execution killed with signal 11 (could be triggered by violating memory limits)