Submission #209715

#TimeUsernameProblemLanguageResultExecution timeMemory
209715AM1648Raspad (COI17_raspad)C++17
0 / 100
87 ms80168 KiB
/* be name khoda */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpii; #define forifrom(i, s, n) for (ll i = s; i < n; ++i) #define fori(i, n) forifrom(i, 0, n) #define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i) #define forir(i, n) forirto(i, n, 0) #define S second #define F first #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() // ---------------------------------------------------------- const ll maxn = 100010; const ll maxm = 50; ll n, m; ll grid[maxn][maxm]; ll dp[maxn][maxm]; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); // ifstream cin("C.in"); cin >> n >> m; fori (i, n) fori (j, m) { char c; cin >> c; grid[i][j] = c == '1'; } ll cc = 0; fori (i, m) { if (grid[0][i] == 1 && grid[0][i + 1] == 0) dp[0][i] = 1, ++cc; } ll ans = cc; forifrom (i, 1, n) { forir (j, m) { if (grid[i - 1][j] && grid[i - 1][j + 1] && !grid[i][j + 1]) { dp[i - 1][j] = dp[i - 1][j + 1]; dp[i - 1][j + 1] = 0; } } fori (j, m) { if (grid[i][j] && grid[i - 1][j]) { dp[i][j] = dp[i - 1][j] + 1; ++cc; dp[i - 1][j] = 0; cc -= dp[i][j - 1]; dp[i][j - 1] = 0; } else if (grid[i][j] && grid[i][j - 1]) { dp[i][j] = dp[i][j - 1]; dp[i][j - 1] = 0; } else if (grid[i][j]) { dp[i][j] = i + 1; cc += i + 1; } } ans += cc; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...