답안 #1070491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070491 2024-08-22T14:41:25 Z 8pete8 웜뱃 (IOI13_wombats) C++17
76 / 100
20000 ms 62032 KB
#include "wombats.h"
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
const int inf=1e9;
int dist[80][202][202],costv[5005][202],costh[5005][200];
int n,m;
int pref[202],root,bound;
int ans[202][202];
vector<vector<int>> mul(vector<vector<int>>a,vector<vector<int>>b){
    vector<vector<int>>ans(m,vector<int>(m,inf));
    for(int i=0;i<m;i++)for(int j=0;j<m;j++)for(int k=0;k<m;k++)ans[i][j]=min(ans[i][j],a[i][k]+b[k][j]);
    return ans;
}
struct seg{
    vector<vector<int>>v[400];
    void build(int l,int r,int pos){
        v[pos].resize(m,vector<int>(m));
        int mid=l+(r-l)/2;
        if(l==r){
            for(int i=0;i<m;i++)for(int j=0;j<m;j++)v[pos][i][j]=dist[l][i][j];
            return;
        }
        build(l,mid,pos*2);
        build(mid+1,r,pos*2+1);
        v[pos]=mul(v[pos*2],v[pos*2+1]);
    }
    void update(int l,int r,int qpos,int pos){
        int mid=l+(r-l)/2;
        if(l==r){
            for(int i=0;i<m;i++)for(int j=0;j<m;j++)v[pos][i][j]=dist[l][i][j];
            return;
        }
        if(qpos<=mid)update(l,mid,qpos,pos*2);
        else update(mid+1,r,qpos,pos*2+1);
        v[pos]=mul(v[pos*2],v[pos*2+1]);
    }
}t;
void cal(int id){
    for(int st=0;st<m;st++)for(int go=0;go<m;go++){
        if(st!=go)dist[id][st][go]=inf;
        else dist[id][st][go]=0;
    }
    //80x200x200x500
    for(int r=(id*root);r<min(n,(id*root)+root);r++)for(int st=0;st<m;st++){
        int mncost=inf,add=0;
        for(int go=0;go<m;go++){
            mncost=min(mncost,dist[id][st][go]-add);
            pref[go]=mncost+add;
            add+=costh[r][go];
        }
        mncost=inf,add=0;
        for(int go=m-1;go>=0;go--){
            mncost=min(mncost,dist[id][st][go]-add);
            dist[id][st][go]=min(pref[go],mncost+add);
            if(r!=n-1)dist[id][st][go]+=costv[r][go];
            if(go)add+=costh[r][go-1];
        }
    }
    //cout<<id<<"PPP\n";
    //for(int i=0;i<m;i++)for(int j=0;j<m;j++)cout<<dist[id][i][j]<<" "<<i<<" "<<j<<"PP\n";
}
void init(int R, int C, int H[5000][200], int V[5000][200]){
    n=R,m=C;
    root=sqrt(n);
    //root=70;
    bound=((n-1)/root);
    for(int i=0;i<n;i++)for(int j=0;j<m-1;j++)costh[i][j]=H[i][j];
    for(int i=0;i<n-1;i++)for(int j=0;j<m;j++)costv[i][j]=V[i][j];
    for(int i=0;i<=bound;i++)cal(i);
    t.build(0,bound,1);
}
//200x200x200xlog(80)
void changeH(int P, int Q, int W){
    costh[P][Q]=W;
    cal(P/root);
    t.update(0,bound,P/root,1);
}
void changeV(int P, int Q, int W) {
    costv[P][Q]=W;
    cal(P/root);
    t.update(0,bound,P/root,1);
}
int escape(int V1, int V2){
    return t.v[1][V1][V2];
}
//70x200x200x500
/*
we can compute [start][at][row] 
=200x200x5000
for each update
how to improve?

use segtree? and matrix [from][go] 200x200
too much memory?


do sqrt decomp instead? trading time for space
split block 

what if we combine both sqrt and segtree 'o'?
we can do qry in
*/

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
wombats.cpp:33:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   33 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
wombats.cpp:39:66: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   39 | vector<vector<int>> mul(vector<vector<int>>a,vector<vector<int>>b){
      |                                                                  ^
wombats.cpp:46:35: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   46 |     void build(int l,int r,int pos){
      |                                   ^
wombats.cpp:57:45: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   57 |     void update(int l,int r,int qpos,int pos){
      |                                             ^
wombats.cpp:68:16: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   68 | void cal(int id){
      |                ^
wombats.cpp:92:59: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   92 | void init(int R, int C, int H[5000][200], int V[5000][200]){
      |                                                           ^
wombats.cpp:103:33: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  103 | void changeH(int P, int Q, int W){
      |                                 ^
wombats.cpp:108:33: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  108 | void changeV(int P, int Q, int W) {
      |                                 ^
wombats.cpp:113:26: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  113 | int escape(int V1, int V2){
      |                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23128 KB Output is correct
2 Correct 3 ms 23128 KB Output is correct
3 Correct 80 ms 25844 KB Output is correct
4 Correct 3 ms 23128 KB Output is correct
5 Correct 3 ms 23132 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6588 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 54 ms 10936 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 11876 KB Output is correct
2 Correct 321 ms 11864 KB Output is correct
3 Correct 343 ms 11608 KB Output is correct
4 Correct 347 ms 11784 KB Output is correct
5 Correct 416 ms 11608 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1441 ms 11784 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 27224 KB Output is correct
2 Correct 5 ms 27372 KB Output is correct
3 Correct 6 ms 27228 KB Output is correct
4 Correct 27 ms 28628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 316 ms 11872 KB Output is correct
2 Correct 294 ms 11696 KB Output is correct
3 Correct 373 ms 11672 KB Output is correct
4 Correct 357 ms 11612 KB Output is correct
5 Correct 370 ms 11788 KB Output is correct
6 Correct 5 ms 27228 KB Output is correct
7 Correct 7 ms 27228 KB Output is correct
8 Correct 5 ms 27152 KB Output is correct
9 Correct 25 ms 28592 KB Output is correct
10 Correct 4 ms 23128 KB Output is correct
11 Correct 4 ms 23132 KB Output is correct
12 Correct 74 ms 25792 KB Output is correct
13 Correct 3 ms 22984 KB Output is correct
14 Correct 3 ms 23132 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6592 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 39 ms 10940 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 1481 ms 11800 KB Output is correct
28 Correct 3467 ms 37932 KB Output is correct
29 Correct 3459 ms 36784 KB Output is correct
30 Correct 3495 ms 36688 KB Output is correct
31 Correct 3615 ms 39464 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 306 ms 11760 KB Output is correct
2 Correct 311 ms 11868 KB Output is correct
3 Correct 340 ms 11788 KB Output is correct
4 Correct 348 ms 11612 KB Output is correct
5 Correct 359 ms 11612 KB Output is correct
6 Correct 5 ms 27228 KB Output is correct
7 Correct 5 ms 27228 KB Output is correct
8 Correct 5 ms 27224 KB Output is correct
9 Correct 27 ms 28760 KB Output is correct
10 Correct 4 ms 23132 KB Output is correct
11 Correct 3 ms 23132 KB Output is correct
12 Correct 39 ms 25936 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 3 ms 23132 KB Output is correct
15 Correct 1216 ms 61468 KB Output is correct
16 Execution timed out 20060 ms 62032 KB Time limit exceeded
17 Halted 0 ms 0 KB -