제출 #723967

#제출 시각아이디문제언어결과실행 시간메모리
723967PoPularPlusPlusRed-blue table (IZhO19_stones)C++17
100 / 100
37 ms10060 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb(e) push_back(e) #define sv(a) sort(a.begin(),a.end()) #define sa(a,n) sort(a,a+n) #define mp(a,b) make_pair(a,b) #define vf first #define vs second #define ar array #define all(x) x.begin(),x.end() const int inf = 0x3f3f3f3f; const int mod = 1000000007; const double PI=3.14159265358979323846264338327950288419716939937510582097494459230; mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); bool remender(ll a , ll b){return a%b;} //freopen("problemname.in", "r", stdin); //freopen("problemname.out", "w", stdout); void solve(){ int n , m; cin >> n >> m; int dp[n+1][m+1],dp1[m+1][n+1]; int mnn = m/2 + 1,mnm = n/2 + 1; int ans = 0; array<int,3> pos; for(int i = 0; i <= n; i++){ for(int j = 0; j <= mnn; j++){ dp[i][j] = i; if(i <= n-mnm)dp[i][j] += j; int rem = m - j; if(rem){ int total = i*mnn-j*i; int less = total / rem; int some = total % rem; if(less+1 <= n-mnm)dp[i][j] += some; if(less <= n-mnm)dp[i][j] += rem - some; } if(dp[i][j] > ans){ ans = dp[i][j]; pos = {0,i,j}; } } } for(int i = 0; i <= m; i++){ for(int j = 0; j <= mnm; j++){ dp1[i][j] = i; if(i <= m-mnn)dp1[i][j] += j; int rem = n - j; if(rem){ int total = i*mnm-i*j; int less = total / rem; int some = total % rem; if(less+1 <= m-mnn)dp1[i][j] += some; if(less <= m-mnn)dp1[i][j] += rem - some; } if(dp1[i][j] > ans){ ans = dp1[i][j]; pos = {1,i,j}; } } } cout << ans << '\n'; char res[n][m]; if(pos[0] == 0){ for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ res[i][j] = '-'; } } for(int i = 0; i < pos[1]; i++){ for(int j = 0; j < pos[2]; j++){ res[i][j] = '+'; } } int left = pos[2] , cur = left; for(int i = 0; i < pos[1]; i++){ int cnt = 0; while(cnt < mnn-pos[2]){ cnt++; res[i][cur] = '+'; cur++; if(cur == m)cur = left; } } for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++)cout << res[i][j]; cout << '\n'; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t;cin>>t; while(t--){ solve(); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

stones.cpp: In function 'void solve()':
stones.cpp:77:15: warning: 'pos.std::array<int, 3>::_M_elems[2]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |     res[i][j] = '+';
      |     ~~~~~~~~~~^~~~~
stones.cpp:75:20: warning: 'pos.std::array<int, 3>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |   for(int i = 0; i < pos[1]; i++){
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...