답안 #737481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737481 2023-05-07T08:30:14 Z keisuke6 육각형 영역 (APIO21_hexagon) C++14
0 / 100
2000 ms 679192 KB
#include "hexagon.h"
#include <vector>
#include <unordered_set>
#include <queue>
long long mod = 1000000007;
using namespace std;
int draw_territory(int N, int A, int B, std::vector<int> D, std::vector<int> L){
  int n = 3000;
  vector<vector<int>> G(n*n);
  int pos = 1500*n+1500;
  unordered_set<int> s;
  vector<int> C = {0,n,n+1,1,-n,-n-1,-1};
  for(int i=0;i<N;i++){
    for(int j=0;j<L[i];j++){
      pos += C[D[i]];
      s.insert(pos);
    }
  }
  for(int i=0;i<n;i++)for(int j=0;j<n;j++){
    if(i != 0) G[i*n+j].push_back((i-1)*n+j);
    if(i < n-1) G[i*n+j].emplace_back((i+1)*n+j);
    if(j != 0) G[i*n+j].emplace_back(i*n+j-1);
    if(j < n-1) G[i*n+j].emplace_back(i*n+j+1);
    if(i != 0 && j != 0) G[i*n+j].emplace_back((i-1)*n+(j-1));
    if(i < n-1 && j < n-1) G[i*n+j].emplace_back((i+1)*n+(j+1));
  }
  vector<int> dist(n*n,1e9);
  vector<bool> seen(n*n,false);
  seen[0] = true;
  dist[pos] = 0;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int po = q.front();
    q.pop();
    for(int x:G[po]){
      if(seen[x] == true || s.count(x)) continue;
      q.push(x);
      seen[x] = true;
    }
  }
  q.push(pos);
  while(!q.empty()){
    int po = q.front();
    q.pop();
    for(int x:G[po]){
      if(dist[x] != 1e9 || seen[x]) continue;
      q.push(x);
      dist[x] = dist[po] + 1;
    }
  }
  long long ans = 0;
  for(int i=0;i<n*n;i++){
    if(seen[i]) continue;
    ans += A+B*dist[i];
    ans %= mod;
  } 
  return (int)((ans+mod)%mod);
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2113 ms 672480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2091 ms 657592 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1914 ms 670400 KB Output is correct
2 Incorrect 1906 ms 670512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1989 ms 679192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2087 ms 665888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1885 ms 670636 KB Output is correct
2 Incorrect 1877 ms 670552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2108 ms 663176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1899 ms 670636 KB Output is correct
2 Execution timed out 2116 ms 641652 KB Time limit exceeded
3 Halted 0 ms 0 KB -