Is vec.resize(n, 0) take more memory than, vec.resize(n) and then intialize by loop???

Правка en2, от gaddopur_coder, 2020-04-19 06:21:04

I solved this problem https://mirror.codeforces.com/problemset/problem/1335/F get memory limit exceed on test case 46 by this solution https://mirror.codeforces.com/contest/1335/submission/76658211 and get accepted by this solution https://mirror.codeforces.com/contest/1335/submission/77233784. I only change the type to resize and initialize the vector vis.resize(n).

vector<vector > vis; vector<vector > cur; vector<vector > dis; vector<vector > siz; vector<vector > r; vector<vector > c; vector<vector > path;

by this get memory limit exceed. vis.resize(n); path.resize(n); cur.resize(n); c.resize(n); dis.resize(n); r.resize(n); siz.resize(n); for(int i = 0; i < n; i++){ vis[i].resize(m, 0); path[i].resize(m); cur[i].resize(m, 0); c[i].resize(m); dis[i].resize(m, -1); r[i].resize(m, -1); siz[i].resize(m, 0); for(int j = 0; j < m; j++){ siz[i][j] = vis[i][j] = cur[i][j] = 0; r[i][j] = dis[i][j] = -1; cin >> c[i][j]; } }

by this get accepted

vis.resize(n);
path.resize(n);
cur.resize(n);
c.resize(n);
dis.resize(n);
r.resize(n);
siz.resize(n);
for(int i = 0; i < n; i++){
    vis[i].resize(m);
    cur[i].resize(m);
    dis[i].resize(m);
    r[i].resize(m);
    siz[i].resize(m);
    c[i].resize(m);
    path[i].resize(m);
    for(int j = 0; j < m; j++){
        siz[i][j] = vis[i][j] = cur[i][j] = 0;
        r[i][j] = dis[i][j] = -1;
        cin >> c[i][j];
    }
}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en9 Английский gaddopur_coder 2020-04-19 06:30:06 0 Tiny change: 'ector;\n\n ve' -> 'ector;\n\n// where n*m <= 1e6;\n\n ve' (published)
en8 Английский gaddopur_coder 2020-04-19 06:29:21 62 Tiny change: 'ector;\n\n ve' -> 'ector;\n\n// where n*m <= 1e6;\n\n ve'
en7 Английский gaddopur_coder 2020-04-19 06:26:47 18 Tiny change: 'ector;\n\n ve' -> 'ector;\n\n// where n*m <= 1e6;\n\n ve'
en6 Английский gaddopur_coder 2020-04-19 06:25:42 24 Tiny change: 'ector;\n\n ve' -> 'ector;\n\n// where n*m <= 1e6;\n\n ve'
en5 Английский gaddopur_coder 2020-04-19 06:24:31 22 Tiny change: 'the vector.\n\nvector' -> 'the vector;\n\nvector'
en4 Английский gaddopur_coder 2020-04-19 06:23:06 2 Tiny change: 'the vector.\n\nvector' -> 'the vector;\n\nvector'
en3 Английский gaddopur_coder 2020-04-19 06:22:32 132
en2 Английский gaddopur_coder 2020-04-19 06:21:04 190
en1 Английский gaddopur_coder 2020-04-19 06:19:12 1857 Initial revision (saved to drafts)