Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CodeChef P1 MATMIN1
#include <bits/stdc++.h> using namespace std; void solve() { int n,m; cin>>n>>m; int a[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>a[i][j]; } } string s; cin>>s; int p,q; cin>>p>>q; map<int,int>mp; map<int,int>total; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(a[i][j]==1){ mp[i+j]++; } total[i+j]++; } } int ct =0; for(int i=0;i<n+m-1;i++){ int num1 = mp[i]; int num0 = total[i]-mp[i]; if(s[i]=='1'){ ct += min(p*num0, q + p*num1); }else{ ct += min(p*num1, q + p*num0); } } cout << ct << "\n"; } int main() { int t; cin>>t; while(t--) { solve(); } }
run
|
edit
|
history
|
help
0
designated-inits
5345
Subset sum
GenericPacker
teste
Kth smallest element
ASHA
Nobita's candies problem
prepend
te lo paso