結果
問題 | No.2934 Digit Sum |
ユーザー |
|
提出日時 | 2025-01-23 22:46:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 319 ms / 2,000 ms |
コード長 | 4,591 bytes |
コンパイル時間 | 1,239 ms |
コンパイル使用メモリ | 149,276 KB |
実行使用メモリ | 426,196 KB |
最終ジャッジ日時 | 2025-01-23 22:46:14 |
合計ジャッジ時間 | 2,773 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:155:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 155 | freopen(task".inp","r",stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:156:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 156 | freopen(task".out","w",stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:160:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 160 | freopen(task1".inp","r",stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:161:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 161 | freopen(task1".out","w",stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
// #pragma GCC optimize("Ofast,unroll-loops")// #pragma GCC target("avx2,tune=native")#include <algorithm>#include <bitset>#include <complex>#include <deque>#include <exception>#include <fstream>#include <functional>#include <iomanip>#include <ios>#include <iosfwd>#include <iostream>#include <istream>#include <iterator>#include <limits>#include <locale>#include <map>#include <new>#include <numeric>#include <ostream>#include <queue>#include <set>#include <unordered_set>#include <sstream>#include <stack>#include <stdexcept>#include <streambuf>#include <string>#include <utility>#include <valarray>#include <vector>#include <cstring>#include <unordered_map>#include <cmath>#include <array>#include <cassert>#include <random>#include <chrono>using namespace std;#define BIT(i,j) (((i)>>(j))&1LL)#define MASK(i) (1LL<<(i))#define ALL(x) (x).begin(),(x).end()#define SZ(x) (int)(x).size()#define fi first#define se second#define ull unsigned long long#define ll long long#define ld long double#define vi vector<int>#define vvi vector<vi>#define vvvi vector<vvi>#define pii pair<int,int>#define vpii vector<pii>#define vvpii vector<vpii>#define REPDIS(i,be,en,j) for(int i = (be); i<=(en); i+=j)#define REPD(i,be,en) for(int i = (be); i>=(en); i--)#define REP(i,be,en) for(int i = (be); i<=(en); i++)#define endl "\n"#define MP make_pair#define int ull//-----------------------------------------------------------------------------------------------//inline void scan(){} template<typename F, typename... R> inline void scan(F &f,R&... r){cin>>f;scan(r...);}inline void print(){} template<typename F, typename... R> inline void print(F f,R... r){cout<<f;print(r...);}//------------------------------------------------------------------------------------------------//const ll LINF = 5e18;const int INF = 1e9;const int LOG = 20;const int MAXN = 1e5+2;const int N = 1e2+3;const int MOD = 1e9+7;const int BASE = 1e5;const ld EPS = 1e-9;const ld PI = acos(-1);const int OFFSET = 1e3;//------------------------------------------------------------------------------------------------//template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }//------------------------------------------------------------------------------------------------///*----------------------------------------------------------------END OF TEMPLATE----------------------------------------------------------------*/int dp[MAXN][163][10];vi a;void solve(){int pos = 0,n,m; cin >> n >> m; ++m;mini(n,162);dp[0][0][0] = 1;for(int i = 0; i<MAXN; i++){for(int j = 0; j<=n; j++){for(int k = 0; k<=9; k++){if(dp[i][j][k]==0) continue;for(int c = 0; c<=9; c++){if(j+c<=n){dp[i+1][j+c][c] += dp[i][j][k];}}}}int sum = 0;for(int j = 0; j<=n; j++){for(int k = 0; k<=9; k++){sum += dp[i+1][j][k];}}if(sum>=m){pos = i+1;break;}}// cout << m << endl;for(int i = 1; i<=pos; i++){for(int j = 1; j<=n; j++){for(int k = 0; k<=9; k++){dp[i][j][k] += dp[i][j-1][k];}}}vi res;for(int i = pos; i>=1; i--){for(int j = 0; j<=9; j++){// cerr << m << " " << dp[i][n][j] << endl;if(m>dp[i][n][j]){m -= dp[i][n][j];}else{assert(n>=j);if(SZ(res)>0 || (SZ(res)==0 && j>0)){res.push_back(j);}n -= j;break;}}}for(int &x:res) cout << x;}signed main(){ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);#define task "test"if(fopen(task".inp","r")){freopen(task".inp","r",stdin);freopen(task".out","w",stdout);}#define task1 "nothing"if(fopen(task1".inp","r")){freopen(task1".inp","r",stdin);freopen(task1".out","w",stdout);}int test = 1;while(test--){solve();}cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";return 0;}/** /\_/\* (= ._.)* / >TL \>AC**/