結果

問題 No.265 数学のテスト
ユーザー IL_mstaIL_msta
提出日時 2015-08-08 02:15:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 3,433 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 91,008 KB
実行使用メモリ 6,608 KB
最終ジャッジ日時 2023-08-16 02:04:16
合計ジャッジ時間 1,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,608 KB
testcase_01 AC 4 ms
5,272 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
#include <sstream>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////

//vector<pair<LL,int>>
string s;
void bbb(int n,vector<pair<LL,int>> * ans){
	
	LL ter=0;
	int X=0;
	for(int i = n;i<s.size();++i){
		if(s[i] == 'd'){
			vector<pair<LL,int>> temp;
			bbb(i+1,&temp);
			//}の位置がほしい
			//i=temp[11];
			//*は無い
			vector<pair<LL,int>>::iterator itr = temp.begin();
			LL t[11];
			for(int asd=0;asd<11;++asd)t[asd]=0;
			for( ;itr != temp.end();++itr ){
				if(itr->second == -1){
					//i = i + 1 + itr->first;
					i = itr->first;
				}else{
					t[itr->second] += itr->first;
				}
			}
			itr = ans->begin();
			for( ;itr != ans->end();++itr ){
				t[itr->second] += itr->first;
			}
			ans->clear();
			for(int asd=0;asd<=10;++asd){
				if( t[asd] != 0){
					ans->push_back(pair<LL,int>(t[asd],asd));
				}
			}
			//temp.clear();
		}else if( s[i] =='+'){
			if(X>0){
				if( ter == 0){
					ans->push_back(pair<LL,int>(1,X));
					//ans[X] += 1;
				}else{
					ans->push_back(pair<LL,int>(ter,X));
					//ans[X] += ter;
					//ter = 0;
				}
				X = 0;
			}else{
				if( ter != 0){
					ans->push_back(pair<LL,int>(ter,0));
				}
				//ans[0] += ter;
			}
			ter = 0;
		}else if( s[i] == 'x'){
			++X;
		}else if( s[i] == '*'){
		}else if( s[i] == '{'){
		}
		else if( s[i] == '}'){
			if(X>0){
				if( ter == 0){
					ans->push_back(pair<LL,int>(1,X));
					//ans[X] += 1;
				}else{
					ans->push_back(pair<LL,int>(ter,X));
					//ans[X] += ter;
					//ter = 0;
				}
				X = 0;
			}else{
				if( ter != 0){
					ans->push_back(pair<LL,int>(ter,0));
				}
				//ans[0] += ter;
			}
			ter = 0;
			LL t[11];
			rep(asd,11)t[asd]=0;
			vector<pair<LL,int>>::iterator itr = ans->begin();
			for( ;itr != ans->end();++itr ){
				if( itr->second > 0){
					t[itr->second-1] += itr->first * (itr->second );
					//itr->first = itr->first * (itr->second );
					//itr->second -= 1;
				}
			}
			ans->clear();
			rep(asd,11){
				if(t[asd] != 0){
					ans->push_back(pair<LL,int>(t[asd],asd) );
				}
			}

			ans->push_back(pair<LL,int>(i,-1));
			//ans[11] = i;
			return ;
		}else{
			if(ter != 0){
				ter = ter * (s[i] - '0');
			}else{
				ter = s[i] - '0';
			}
		}
	}
	if(X>0){
		if( ter == 0){
			ans->push_back(pair<LL,int>(1,X));
			//ans[X] += 1;
		}else{
			ans->push_back(pair<LL,int>(ter,X));
			//ans[X] += ter;
			//ter = 0;
		}
		X = 0;
	}else{
		if( ter != 0){
			ans->push_back(pair<LL,int>(ter,0));
		}
		//ans[0] += ter;
	}
	ter = 0;

	return ;
}

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(16);//
	
	int N,d;
	//string s;
	cin>>N>>d>>s;
	vector<pair<LL,int>> ans;
	bbb(0,&ans);
	vector<pair<LL,int>>::iterator itr = ans.begin();
	LL temp[11];
	rep(i,11)temp[i] = 0;
	for(; itr != ans.end();++itr ){
		temp[itr->second] += itr->first;
	}
	for(int i=0;i<=d;++i){
		cout << temp[i];
		if(i != d){
			cout << " ";
		}else{
			cout << endl;
		}
	}
	return 0;
}
0